- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Seperating data from a file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-17-2008 10:53 AM
тАО12-17-2008 10:53 AM
Seperating data from a file
I attaching a file,
in that file every record starts with PURCHASE ORDER NUMBER,
so I want to seperate the every record starts with PURCHASE ORDER NUMBER and create a new file for every one records,
how can I used grep command
please advise me
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-17-2008 10:59 AM
тАО12-17-2008 10:59 AM
Re: Seperating data from a file
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-17-2008 11:14 AM
тАО12-17-2008 11:14 AM
Re: Seperating data from a file
i bet Verizon won't be too pleased to see this kind of info posted on a public forum.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-17-2008 11:21 AM
тАО12-17-2008 11:21 AM
Re: Seperating data from a file
Please find the attachment
I want to generate new files for every record in the attached file
In the attached file
for example in the attached file
one record is in italic and bold
and other record is plane
I want to create 2 files, one file for Italic and bold record and second file for the plane text record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-17-2008 12:26 PM
тАО12-17-2008 12:26 PM
Re: Seperating data from a file
But AWK ro PERL woudl be happy to.
For example, if you want to create files called S0155807.tmp where S0155807 is the
PURCHASE_ORDER_NO then you coudl simply use:
awk '/^PURCHASE_ORDER_NO:/{file=$2 ".tmp"} file { print >> file}' your-file
So there are 2 lines in this 'script':
/^PURCHASE_ORDER_NO:/{file=$2 ".tmp"}
That says, IF you see a line STARTING with PU... THEN set variable 'file' to the concatenation of field 2 on the line with the string ".tmp"
Next line:
file { print >> file}
That says... IF variable 'file' is set THEN APPEND the input line ($0) to the fiel with the name in variable 'file'.
Enjoy!
and... uh... let's just pretend those were mock-up names and phone numbers you posted there in a public forum huh? This time.
And there won't be a next time right?
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2008 06:56 AM
тАО12-18-2008 06:56 AM
Re: Seperating data from a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2008 07:34 AM
тАО12-18-2008 07:34 AM
Re: Seperating data from a file
awk command is working fine when I use from command line,
when I use the command in the script and specifying the file path it is not working
eg
awk '/^PURCHASE_ORDER_NO:/{file=$2 ".tmp"} file { print >> file}' /home/abc/abc.txt
could you please advise me who to specify the file path
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2008 07:41 AM
тАО12-18-2008 07:41 AM
Re: Seperating data from a file
He wants to seperate 1 complete record to a file and so on. So that each new file contains all the information of that purchase record.
Something like this might do the trick :P but as I don't have access to a shell atm this isn't tested.
#!/bin/bash
# Set arguments to variables
# Which file to parse from
input_file=$1
# The standard which output files will be named in, ex. order-S0155806
namestd=$2
# Change IFS to handle newlines instead of space
IFS="\n"
for i in $(cat $input_file); do
# Just to check if we are going to start a new file or not
echo $i | grep "PURCHASE_ORDER_NO:" &> /dev/null
if [ $? -eq 0 ]; then
# Get the order id number to seperate the files from each other
orderid=$(echo $i | sed -e "s/^PURCHASE_ORDER_NO: *\([A-Za-z0-9]\) *$/\1/")
# Create the new filename
output_file="$namestd-$orderid"
fi
# Write the output to the file.
echo $i >> $output_file
done
(And yes, it's a slow day and I'm bored :P)
Best regards
Fredrik Eriksson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2008 09:09 AM
тАО12-18-2008 09:09 AM
Re: Seperating data from a file
Hmmm...
Errors?
'Nothing happens'?
Files create in places you did not expect?
>> awk '/^PURCHASE_ORDER_NO:/{file=$2 ".tmp"} file { print >> file}' /home/abc/abc.txt
Apparently you needed to epxlicitly specify the input.
You may need to expllicitly specify the output.
To do this you may want to change:
file=$2 ".tmp"
to
file= "/home/abc/" $2 ".tmp"
Good luck,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2008 02:00 PM
тАО12-18-2008 02:00 PM
Re: Seperating data from a file
As per ur suggestion I used the command in the script, the multiple files creating,
I want to pick each file and send email, one email for one file, if it creates 100 files, it should send 100 emails
could you please tell me how to process
Here I am using pick one file and send email,
how can I handle multiple files to send email, with file name starts with $2".tmp"
if test -s "${input_file:?}"
then
elm -s "${email_subject:?}" \
"${email_recipients[@]:?}" < "${input_file:?}"
Thanks