![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can I use sed to insert a string which has colon | Jenny.palmy | UNIX for Dummies Questions & Answers | 2 | 04-28-2008 08:04 PM |
| Read text file from a specified string to the end | bsrajirs | UNIX for Advanced & Expert Users | 9 | 01-11-2008 01:05 AM |
| Read string from a file,plz help me to check | joshuaduan | Shell Programming and Scripting | 1 | 05-11-2007 04:12 AM |
| Failed to insert string into file before line | nir_s | Shell Programming and Scripting | 7 | 07-26-2005 02:37 AM |
| vector<string> with insert cmd | photon | High Level Programming | 1 | 09-10-2004 06:51 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How to insert a string at the end of a file read
Hi,
This thread is an extension of the post I posted in another folder for Unix Dummies. I am actually trying to read all the files in a folder, let say folder A. There are alot of .txt files in this folder where I have sed them and translate to numeric elements. For example:- I have 0,0,0,0,0,0,0,0,0,....... Firstly, I have problem where I would like to insert a string "test" for the last element of each file read; lets say:- 0,0,0,0,0,0,0...........,test Second, I would like to insert a newline character before next file is read similarly. Please advise. Thanks. -Jason |
|
||||
|
Quote:
I hope END in gawk/nawk script will do your first requirment .. user_prady |
|
||||
|
Hi reborg,
Thanks for the input. I tried to simulate them when I have a file described. Could you explain to me what these does ; I understand that FNR stands for current record number in filename which is 1 However, i do not understood why NR>FNR . Is that for inserting a new line which is {print ""} ? awk 'FNR == 1 && NR > FNR { print "" } { print $0 ",test" }' *.txt Actually, my file structure is originally not from the format of 0,0,0,0,1,0,0. Rather, I have a C file where I extract the first field of all the files and arranged into the above mentioned format. Below is the code from my original file to the above mentioned format. cat b*.txt| sed 's/^[ ]*//' |sed 's/^-/0/'|sed 's/^#####/0/'|sed '/^[^0-9-]/d'|tr ':' "," |awk ' { printf ("%s",$1); }'>> output.txt I tried to apply the code that you pointed to me in this scenario but it doesnt allow to work. Please advise. Appreciate alot. Thanks. -Jason |
|
||||
|
Hi,
from the above code, I tried something like this:- cat b*.txt| sed 's/^[ ]*//' |sed 's/^-/0/'|sed 's/^#####/0/'|sed '/^[^0-9-]/d'|tr ':' "," |awk '{printf ("%s",$1);}'| awk 'FNR == 1 && NR > FNR { print "" } { print $0 ",test" }' >>output.txt However, given I have two files, the "string" of "test" is only appended at the end of reading these files. Any idea how to break the file apart to that new line and "test" can be inserted?Thanks. -Jason |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|