- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- 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
Forums
Discussions
Discussions
Discussions
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2008 09:17 PM
12-18-2008 09:17 PM
Re: Seperating data from a file
for file in what-ever; do
mailx -s "${email_subject:?}" "${email_recipients[@]:?}" < $file
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2008 04:48 AM
12-19-2008 04:48 AM
Re: Seperating data from a file
u specified as
"for file in what-ever; do"
what-ever means?
I have to specify anything, could you please example
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2008 05:47 AM
12-19-2008 05:47 AM
Re: Seperating data from a file
You need to mention how you get those 100 files. If you do them one by one, then you can remove that for loop and just use $2.tmp.
If you are going to do them all at once, you will need to get a list of those files. Either from ls(1) or from a file. You need to be more specific where that mail command goes after you create the file(s).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2008 06:01 AM
12-19-2008 06:01 AM
Re: Seperating data from a file
In that case you need to read each PO file and extract the name and then convert that to an email address based on whatever format you use.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2008 06:13 AM
12-19-2008 06:13 AM
Re: Seperating data from a file
'WHAT PROBLEM ARE YOU REALLY TRYING TO SOLVE'.
WHY stick each order in a unique file, only to Email thme out? a SHELL or PERL script could just keep all data in memory and call mail directly from a sub-process feeding it the lines without ever needing a temp file to hold an order.
The AWK script could easily detect the new order condition END as well as the already present /^PURCHASE_ORDER_NO/ test, and then just do the Email of the past order right there and then, re-suing the same file (name) for the next order, renaming failed sends to a file to remain on the box with the order number in the file. Or in sticking with the unique names, perhaps delete succesfully send temp files.
HOW will you determine the "to:" Email address? Can that be integrated in the scripts? Perhaps a helper file with (phone) number to Email mapping?
Good luck!
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2008 03:32 PM
12-19-2008 03:32 PM
Re: Seperating data from a file
Now I am able to send individual email for every individual file by the using the below code
for file in `ls /home/abc/*.tmp`
do
if test -s "${file:?}"
then
elm -s "${email_subject:?}" "${email_recipients[@]:?}" < $file
fi
done
Now I want to use only file name from the /home/abc directory and place that filename in the email subject for every email
the email subject should be like this "welcome abc.txt"
how can I place name of the file in the code could you please help me
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2008 04:29 PM
12-19-2008 04:29 PM
Re: Seperating data from a file
filename=`basename $file`
elm -s "$filename" "${email_recipients[@]:?}" < $file
You can append or prepend any other text in the filename variable