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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to extract columns from a text file ihot Shell Programming and Scripting 16 05-05-2008 08:33 PM
c program to extract text between two delimiters from some text file kukretiabhi13 High Level Programming 5 01-22-2008 02:42 AM
How to extract text from xml file chrisf Shell Programming and Scripting 3 09-01-2007 11:25 AM
merging few columns of two text files to a new file kolvi Shell Programming and Scripting 4 09-15-2005 01:34 AM
How to extract data from a text file negixx Shell Programming and Scripting 1 07-19-2005 06:30 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-19-2007
Registered User
 

Join Date: Oct 2007
Posts: 30
Extract text in 2 columns of output file.

Hello!!
I have the text file with following format...

--SubTotal-----------------------------------0--161---------------44---13739369-67---
--SubTotal-----------------------------------0--147---------------0----49643---1----
--SubTotal-----------------------------------0--161---------------20---13750219-31---
--SubTotal-----------------------------------0--147---------------0----49679---0----


I want to extract bold figures in two different columns of output file.
Line 1 and 3 in 1st column while line 2 and 4 in second column.

Please help me in this regard.
Is it possile that i pass my test file in an argument of the script.

Thanks a lot.
BR
Danish
Reply With Quote
Forum Sponsor
  #2  
Old 10-19-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
Code:
sed 's/--*/-/g' filename | awk -F"-" '{ printf "%s", $6; getline; split($0, arr, "-"); printf " %s\n", arr[6] }'
Reply With Quote
  #3  
Old 10-19-2007
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,907
Quote:
Originally Posted by Danish Shakil View Post
Hello!!
I have the text file with following format...

--SubTotal-----------------------------------0--161---------------44---13739369-67---
--SubTotal-----------------------------------0--147---------------0----49643---1----
--SubTotal-----------------------------------0--161---------------20---13750219-31---
--SubTotal-----------------------------------0--147---------------0----49679---0----


I want to extract bold figures in two different columns of output file.
Line 1 and 3 in 1st column while line 2 and 4 in second column.
[...]
Code:
awk 'NR%2?$0=$6:$0=" "$6"\n"' ORS= FS="--*" filename
Use /usr/xpg4/bin/awk on Solaris.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0