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
c program to extract text between two delimiters from some text file kukretiabhi13 High Level Programming 7 12-03-2008 06:29 PM
how to extract columns from a text file ihot Shell Programming and Scripting 16 05-06-2008 12:33 AM
How to extract text from xml file chrisf Shell Programming and Scripting 3 09-01-2007 03:25 PM
merging few columns of two text files to a new file kolvi Shell Programming and Scripting 4 09-15-2005 05:34 AM
How to extract data from a text file negixx Shell Programming and Scripting 1 07-19-2005 10:30 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 10-19-2007
Danish Shakil Danish Shakil is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 35
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
  #2 (permalink)  
Old 10-19-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958

Code:
sed 's/--*/-/g' filename | awk -F"-" '{ printf "%s", $6; getline; split($0, arr, "-"); printf " %s\n", arr[6] }'

  #3 (permalink)  
Old 10-19-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,926
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.
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:24 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