The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
Append each line to next previous line in a file sudhakaryadav Shell Programming and Scripting 8 06-01-2009 12:21 PM
Append line that does not contain pipe to it previous line ainuddin Shell Programming and Scripting 11 11-11-2008 10:58 AM
Joining lines in reverse. append line 1 to line 2. dwalley Shell Programming and Scripting 7 08-04-2008 08:11 AM
How to append some strings line by line? xinoo Shell Programming and Scripting 4 06-24-2008 03:04 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

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-27-2009
kshuser kshuser is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 30
append last line

Suppose i have a file FILE1.TXT

Code:
2293847982374 sdj 23423
2298372038974 dsj 23492
2972837629376 abj 34929
2984836398384 abc 39723

I want to append the above FILE1.TXT with total no of records and appending to the last line with "3000004" total 7 digits only, if 12 records then "3000012" to bottom of the line, in this case below

Code:
2293847982374 sdj 23423
2298372038974 dsj 23492
2972837629376 abj 34929
2984836398384 abc 39723
3000004

regards

Last edited by vgersh99; 10-27-2009 at 01:06 PM.. Reason: fixed code tags
  #2 (permalink)  
Old 10-27-2009
protocomm protocomm is offline
Registered User
  
 

Join Date: Mar 2009
Location: france, montpellier
Posts: 150

Code:
awk 'END{print $0,"\n""3000004"}1' file

  #3 (permalink)  
Old 10-27-2009
kshuser kshuser is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 30
Quote:
Originally Posted by protocomm View Post
Code:
awk 'END{print $0,"\n""3000004"}1' file
the no of records is not always the same. In the Input file there may be some more than 100 records we dont no...

BTW the above code has syntax error

Code:
>awk 'END{print $0,"\n""3000004"}1' file1.txt
awk: syntax error near line 1
awk: bailing out near line 1


Last edited by pludi; 10-27-2009 at 01:04 PM.. Reason: code tags please...
Bits Awarded / Charged to kshuser for this Post
Date User Comment Amount
10-27-2009 pludi code tags added - 3K charge -3,000
  #4 (permalink)  
Old 10-27-2009
protocomm protocomm is offline
Registered User
  
 

Join Date: Mar 2009
Location: france, montpellier
Posts: 150
I have bash and it's works fine,but perhaps you have another shell.
  #5 (permalink)  
Old 10-27-2009
radekr radekr is offline
Registered User
  
 

Join Date: Jan 2009
Location: Czech Republic
Posts: 6
append last line

simple:
echo "3000004" >> FILE1.TXT
  #6 (permalink)  
Old 10-27-2009
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,440

Code:
awk 'NF{c++;print} END{print (3000000 + c)}' inFile

  #7 (permalink)  
Old 10-27-2009
kshuser kshuser is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 30
Quote:
Originally Posted by danmero View Post
Code:
awk 'NF{c++;print} END{print (3000000 + c)}' inFile
i am getting syntax error as i want this in KSH script


Code:
>awk 'NF{c++;print} END{print (3000000 + c)}' ein_data_file.txt > ein_data_file1.dat
awk: syntax error near line 1
awk: bailing out near line 1


Last edited by vgersh99; 10-27-2009 at 02:38 PM.. Reason: fixed code tag
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0