![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Append text at end of the first line in a file | catgovind | Shell Programming and Scripting | 7 | 05-01-2008 08:33 AM |
| Append to end of each line of file without a temp file. | rorey_breaker | Shell Programming and Scripting | 4 | 04-03-2008 11:11 AM |
| append a line to the last line in a file | subhrap.das | UNIX Desktop for Dummies Questions & Answers | 5 | 04-25-2007 10:17 AM |
| Append a field to the end of each line of a file based on searching another file. | ultimate | Shell Programming and Scripting | 2 | 03-29-2005 11:21 AM |
| Large file need to append to each line | r1500 | UNIX for Dummies Questions & Answers | 1 | 10-14-2003 11:48 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi,
We have Multiple source files which has some data, I need a K shell script which will append number '1' as the last character to all the lines of the first file and then increments the value and appends '2' to all the lines to the next file and so on. For Example Incoming file 1 a,aa,aa,a,aa b,bb,bb,b,bb Incoming file 2 c,cc,cc,c,cc d,dd,dd,d,dd the Output should be Incoming file 1 a,aa,aa,a,aa,1 b,bb,bb,b,bb,1 Incoming file 2 c,cc,cc,c,cc,2 d,dd,dd,d,dd ,2 Can anyone Plz help me on this. Thanks Sunny. |
|
||||
|
I am getting the header and detail records in the same file. they dont have a common key. what i am supposed to do is to break each file depending on a fixed header rows and then load them to a seperate file, But we need a Common key to join them in the ETL so the Number i wanted to append at the end of each record will act as a reference and helps me to do that. I am able to split the File in to 2 parts depending on the no of header records.
but where i am stuck is i have to append a number at the end of each line in a file and that number needs to increment for each file Below is my code #Arguments DIRECTORY=$1 FILE=$2 NO_HEADER=$3 #Validating the Arguments if [ $# -lt 1 ] then echo echo "\n Error :$0 Usage Input File \n" echo exit 1 # splits up the Header File head -$NO_HEADER $DIRECTORY/$FILE > $DIRECTORY/${FILE}.head echo `cat $DIRECTORY/${FILE}.head | awk 'BEGIN {FS = "," } ; { printf ("%s,", $2) }'` > $DIRECTORY/${FILE}.Header rm -f $DIRECTORY/${FILE}.head #calculates the remaining records in the File and writes them into the Detail file NO_TAIL=`expr $NO_LINES - $NO_HEADER` tail -$NO_TAIL $DIRECTORY/$FILE > $DIRECTORY/${FILE}.detail Please help |
|
||||
|
Try this if awk is allowed, it creats the files "newfile.1", "newfile.2", "newfile.3" and so on.
Code:
awk '
!infile{infile=FILENAME;nr=1}
infile!=FILENAME{infile=FILENAME;close("newfile."nr);nr++}
{print $0","nr >> "newfile."nr}
' file1 file2 file3
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|