- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Please help me, need help to modify a file usi...
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
01-11-2002 01:28 PM
01-11-2002 01:28 PM
I need to relese a script by today itself. please help me to do this.
I have a big file lets say 65 thousand lines. it is a tab seperated text file. i need to add one more columne at the end of every line ( tab seperated). the value of that column is the first column of the first line.
example:
Inputfile:
NY^hhhhh^hhhhh^kkkkk^gggg
hhh^jjjjj^9999^44444
888^hhhh^443444^hhhhhh
Output file
NY^hhhhh^hhhhh^kkkkk^gggg^NY
hhh^jjjjj^9999^44444^NY
888^hhhh^443444^hhhhhh^NY
here '^' represent tab character.
please help me ASAP.
vivek S.
viveks@fox.com
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2002 01:42 PM
01-11-2002 01:42 PM
Re: Please help me, need help to modify a file using awk or sed
Use,
sed "s/$/^NY/g" OLD_FILE >NEW_FILE
Hope this helps.
Regds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2002 01:43 PM
01-11-2002 01:43 PM
Re: Please help me, need help to modify a file using awk or sed
Consider this:
# echo "a 123\nb 456\nc 789"|awk '{if (NR==1) X=$1;print $0"\t"X}'
Thus,
# awk '{if (NR==1) X=$1;print $0"\t"X}' myfile.in > myfile.out
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2002 01:49 PM
01-11-2002 01:49 PM
Re: Please help me, need help to modify a file using awk or sed
BEGIN { FS ="\t" }
/^[a-z]/ {print $0, $1}
/^[A-Z]/ {print $0, $1}
/^[0-9]/ {print $0, $1}
Then call the script by
awk -f awkfile yourfilename > yourfilename1
GL,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2002 01:52 PM
01-11-2002 01:52 PM
Re: Please help me, need help to modify a file using awk or sed
I'll modify to fit.
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2002 01:59 PM
01-11-2002 01:59 PM
Solution1. Get the first word in the fist line (Do you have comments?)
WORD=`head -1 file |awk '{print $1}'`
2. Replace the end of line with $WORD
sed 's/$/ '$WORD'/' file > result
Note the space after $/
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2002 02:14 PM
01-11-2002 02:14 PM
Re: Please help me, need help to modify a file using awk or sed
In case you don't have what you want yet...
Using awk (one liner):
awk -v EXT=`head -1 infile | awk '{print $1}'` '{print $0"\t"EXT}' infile
Using sed:
EXT=`head -1 infile | awk '{print $1}'`
sed "s/$/ $EXT/" infile
Note the "white space" before $EXT in the sed example is a single tab character.
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2002 02:18 PM
01-11-2002 02:18 PM
Re: Please help me, need help to modify a file using awk or sed
since i am using Sridhar's idea, so 10 points goes to Sridhar.
thanks again.
vivek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2002 02:23 PM
01-11-2002 02:23 PM
Re: Please help me, need help to modify a file using awk or sed
I am feeling guilty now.
You need to give points to everyone or ignore all. It is not that we sell our ideas here for points. And moreover it is not about points but the feedback and saying thanks to others for spending their time for you. You will not run out of points if you keep giving them.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2002 02:26 PM
01-11-2002 02:26 PM
Re: Please help me, need help to modify a file using awk or sed
For the record, you can assign points to no one, some, or all, equally, or on a scale based on the merit, *regardless* of which solution you ultimately choose. See here:
http://us-support2.external.hp.com/estaff/bin/doc.pl/forward/screen=estaffAssistance/sid=748a3f351af90e834c?Page=file0002#forpoints
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2002 02:29 PM
01-11-2002 02:29 PM
Re: Please help me, need help to modify a file using awk or sed
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2002 03:24 PM
01-11-2002 03:24 PM
Re: Please help me, need help to modify a file using awk or sed
i was trying following command and it was not working. i don't know why? please someone explain me.
vv=`head -1 BP|awk '{print substr($0,1,2)}'`
echo $vv
awk '{print $0,$vv}' BP >BP_3
please help me to understand awk command.
thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2002 03:40 PM
01-11-2002 03:40 PM
Re: Please help me, need help to modify a file using awk or sed
OK, you're taking the first line of a file named "BP" and assigning the first two characters of the first line to the variable 'vv'.
Then, you echo the value of 'vv' to stdout.
Lastly, you are attempting to append the value of 'vv' to the end of each line of the file 'BP' creating file 'BP_3'.
BUT, your syntax is wrong, It should be:
# awk -v vv=$vv '{print $0,vv}' BP > BP_3
...OR...
# awk '{print $0,vv}' vv=$vv BP > BP_3
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2002 03:43 PM
01-11-2002 03:43 PM
Re: Please help me, need help to modify a file using awk or sed
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2002 03:57 PM
01-11-2002 03:57 PM
Re: Please help me, need help to modify a file using awk or sed
Excuse me. If I helped you, please remember to assign points for my time and effort. Thank you.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2002 04:20 PM
01-11-2002 04:20 PM
Re: Please help me, need help to modify a file using awk or sed
Thanks