The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
usage of module Text::Wrap; trek Shell Programming and Scripting 3 06-05-2008 02:08 AM
word wrap issue with grep bowtiextreme HP-UX 4 04-30-2008 07:39 PM
SCO acquisition wrap-up iBot UNIX and Linux RSS News 0 02-19-2008 05:30 PM
Wrap Interactive Script meskue Shell Programming and Scripting 0 06-23-2006 06:21 PM
word wrap in vi dangral UNIX for Dummies Questions & Answers 3 10-30-2002 02:45 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 05-03-2006
vanda_25 vanda_25 is offline
Registered User
  
 

Join Date: May 2006
Posts: 4
Exclamation Should I use sed/ grep/awk for wrap file?

Hi,
This is my first time post a new thread. I have been trying to work on this for the past 2 days and could not find any good solution.
I have 1 long long line ( EDI wrapped file) like below:
NEW*SR*04411763447*279*278*Q~*ZR*AAV*SR*04511763460*SQ*21B37F04~HL*305*304*Q~K~SN1*1*1*SR*0551176346 1* and so on...all in 1 long line.

I need to extract certain pattern =grep 'SR\*[0-9]\{11\}\*' ( example SR*04411763447*) and remove others and put it to output file like:
SR*04411763447*
SR*04511763460*
SR*05511763461*
.
. etc.

I tried use grep and sed..but have no luck working on wrap file.
Please help.

Last edited by vanda_25; 05-03-2006 at 01:17 PM..
  #2 (permalink)  
Old 05-03-2006
hegemaro hegemaro is offline
Registered User
  
 

Join Date: Feb 2006
Location: Schenectady, NY
Posts: 134
I've been working with X12 documents for the last year and a half and finally wrote a C program to print out the segments one per line. However, a nice quick-and-dirty trick is to convert the segment terminator (usually, but not always, a tilde) to a newline.

# cat file | tr '~' '\n' | grep 'SR\*[0-9]\{11\}\*'
  #3 (permalink)  
Old 05-03-2006
vanda_25 vanda_25 is offline
Registered User
  
 

Join Date: May 2006
Posts: 4
Thank you so much. I wish I post this 2 days ago.
I added cut cmd..a bit tuning and it should be ok.
cat file.txt |tr '~' '\n' | grep 'SR\*[0-9]\{11\}\*'| cut -c 75-85 >final.txt

Thanks a bunch.
  #4 (permalink)  
Old 05-03-2006
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
You can also use:
Code:
echo $LINE|awk 'FS="\*" {for (i = 1; i <= NF; ++i){ if ($i ~ /[0-9]{11}/) print $i }}'
Regards
  #5 (permalink)  
Old 05-03-2006
vanda_25 vanda_25 is offline
Registered User
  
 

Join Date: May 2006
Posts: 4
Hi Klashxx, could you break up the awk command that you posted? Thx
  #6 (permalink)  
Old 05-04-2006
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
Code:
$ cat fields.dat 
NEW*SR*04411763447*279*278*Q~*ZR*AAV*SR*04511763460*SQ*21B37F04~HL*305*304*
     R*01234567891*279*278*Q~*ZR*AAV*SR*04511763460*SQ*21B37F04~HL*305*304*
NEW*SR*09876543210*279*278*Q~*ZR*AAV*SR*04511763460*SQ*21B37F04~HL*305*304*
$ cat fields.awk 
awk '{

FS="\*"

{
for (i = 1; i <= NF; ++i)
   { 
   if ($i ~ /[0-9]{11}/) 
   print $i 
   }
}

}' 
$ fields.awk <fields.dat
04411763447
04511763460
01234567891
04511763460
09876543210
04511763460
Cheers
  #7 (permalink)  
Old 05-04-2006
vanda_25 vanda_25 is offline
Registered User
  
 

Join Date: May 2006
Posts: 4
Hi Klashxx,
I got an error that said:
awk: Input line ISA*00* *00 cannot be longer than 3,000 bytes.
I guess my input file is too big to handle for awk? My files mostly more than 1200 Kilo bytes.
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 04:04 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