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
plz help me in writing a script Renjesh SUN Solaris 3 03-24-2008 08:31 AM
Writing the script jess_t03 Shell Programming and Scripting 1 10-10-2007 06:17 AM
plz help in writing awk script LAKSHMI NARAYAN Shell Programming and Scripting 3 07-14-2007 04:06 AM
Writing Script? wmosley2 Shell Programming and Scripting 15 01-12-2004 05:01 PM
need help writing a script tarballed Shell Programming and Scripting 3 04-17-2003 05:50 PM

Closed Thread
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 08-25-2007
dr46014 dr46014 is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 94
help writing script

hi all
i am having a file(a fixed length file) of 28 bytes.The file has account number from 5th place to next 16 digits.
the file looks like below,

58331600563588885696ACXT5263
58331600563588885697ACXT5263
58331600563588885698ACXT5263

i want to write a script which will extract the account number from 5th palce to length 16 and append ' before and afeter that and , after each line except the last one.
my out put should look like

'600563588885696',
'600563588885697',
'600563588885698'

please help me in writing a shell script
  #2 (permalink)  
Old 08-25-2007
kduffin's Avatar
kduffin kduffin is offline Forum Advisor  
UN1X
  
 

Join Date: Nov 2003
Location: Maryland
Posts: 449
What's the purpose - would appreciate a reply as it sounds like homework. Simple enough though:

cat filename | cut -c6-20 | sed -e"s/^/'/;s/$/'/"

Whoops didn't see the ',' - your part of the homework? Easy enough as well, but grades should be earned.

Cheers,

Keith
  #3 (permalink)  
Old 08-25-2007
dr46014 dr46014 is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 94
my purpose was to add a ',' after each line except the last one.can u please guide me how to do this
  #4 (permalink)  
Old 08-25-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,553
Quote:
Originally Posted by kduffin View Post
What's the purpose - would appreciate a reply as it sounds like homework. Simple enough though:

cat filename | cut -c6-20 | sed -e"s/^/'/;s/$/'/"

Whoops didn't see the ',' - your part of the homework? Easy enough as well, but grades should be earned.

Cheers,

Keith
no need for cat.
Code:
cut -c6-20 filename | sed .....
  #5 (permalink)  
Old 08-25-2007
kamitsin's Avatar
kamitsin kamitsin is offline
Registered User
  
 

Join Date: Nov 2006
Location: /dev/null
Posts: 177
cut -c "6-20" am|awk '{print "`",$1,"`"}'
  #6 (permalink)  
Old 08-25-2007
dr46014 dr46014 is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 94
how can i add comma after each line except the last one
  #7 (permalink)  
Old 08-25-2007
kamitsin's Avatar
kamitsin kamitsin is offline
Registered User
  
 

Join Date: Nov 2006
Location: /dev/null
Posts: 177
Code:
cut -c "6-20" am|sed -e"s/^/'/;s/$/',/"|sed '$s/,//'
Cheers,
K
Closed Thread

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 08:21 PM.


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