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. Shell Script Page.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
retrieved multiple lines on multiple places in a file dala Shell Programming and Scripting 8 03-14-2008 11:28 AM
error: initializer expression list treated as compound expression arunchaudhary19 High Level Programming 12 11-16-2007 02:44 AM
Expression for Finding Multiple Directories..?? meskue Shell Programming and Scripting 3 07-10-2006 12:04 PM
How to choose Multiple process or Multiple threads? ashleykumar IP Networking 0 04-10-2006 03:30 AM
Regular Expression + Aritmetical Expression Z0mby Shell Programming and Scripting 2 05-21-2002 07:59 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-15-2008
Registered User
 

Join Date: May 2008
Posts: 51
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
need help on multiple expression

this is the content of the file:

Quote:
AutoMicro Job Request
================================
(1). Job Request Information
================================
Date of Request: 20080514 10:37 Submitted By: xxx
First Carrier: xxx Date of Process: 20080514 10:38

================================
(2). Plan Summary By Connection
================================
| Previous | | Current |
Conn Total Plan Usr Prev Can Has
Vsl Voy Type Qty Qty Plan Plan Plan Plan Reason**
--- --- ---- ----- --- ---- ---- ---- ---- ------
xxx 254 xxx 11 0 0 0 11 11
**Reason: [P]: Cannot Plan Fully [O]: Not In Planning Scope [C]: No Cluster
[b]: Big Volume [i]: Band 1 HLD Connection [S]: Not Selected
[N]: No BKDN to Plan [H]: Holding Volume Too High [F]: No Feasible space

==========================================
(3). Plan Details For Connecting Carriers
==========================================
Vsl Voy Port Sz Cat Wt Block Slot Row Qty Crane OperCode ResvFor
xxx 254 xx 40 HC M U02 25 6 4 0
xx 20 GP H U02 27 3 1 0
xx 20 GP U U02 27 3 1 0
xx 40 HC X U02 25 4 3 0
xx 40 HC U U02 25 6 1 0
xx 20 GP L U02 27 3 1 0
i want to remove both the line starting with "=" and "(" but i can only remove one at a time..so how do I go about removing both of them?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-15-2008
rubin's Avatar
Registered User
 

Join Date: Nov 2007
Posts: 134
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Quote:
Originally Posted by finalight View Post
...
i want to remove both the line starting with "=" and "(" but i can only remove one at a time..so how do I go about removing both of them?
One way:

Code:
awk  '!/^\=+/ && !/^\(/ '  your_file
Reply With Quote
  #3 (permalink)  
Old 05-15-2008
Registered User
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 233
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Something like this?

Code:
grep -v '^[(=]' inputfile > outputfile
Reply With Quote
  #4 (permalink)  
Old 05-15-2008
Registered User
 

Join Date: May 2008
Posts: 51
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
now i got another problem

my dashes "---" "---" are not at the first line, and iwant to remove them as well
however when i try to do this:

Quote:
grep -v '[=-(]' test.txt
it won;t remove the dashes at all
Reply With Quote
  #5 (permalink)  
Old 05-15-2008
Registered User
 

Join Date: May 2008
Posts: 51
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Quote:
Originally Posted by rubin View Post
One way:

Code:
awk  '!/^\=+/ && !/^\(/ '  your_file
can you please explain the pattern to me?

and it says event not found
Reply With Quote
  #6 (permalink)  
Old 05-15-2008
rubin's Avatar
Registered User
 

Join Date: Nov 2007
Posts: 134
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
To remove the dashes too, use:

Code:
awk '!/^\=+|^\(|^\-+/' your_file
If your OS doesn't recognize awk , try nawk or /usr/xpg4/bin/awk on solaris.
Reply With Quote
  #7 (permalink)  
Old 05-15-2008
Registered User
 

Join Date: May 2008
Posts: 51
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
it recognizes awk, but it doesn't recognizes '/^\' this particular pattern
Reply With Quote
  #8 (permalink)  
Old 05-15-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,253
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
"Event not found" is a message from your shell. You need to use different quoting (though I don't understand how it could say that if you use single quotes; which shell are you using?)
Reply With Quote
  #9 (permalink)  
Old 05-15-2008
Registered User
 

Join Date: May 2008
Posts: 51
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
should be korn shell
Reply With Quote
  #10 (permalink)  
Old 05-15-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,253
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
If you are on Solaris or HP-UX, did you try looking for nawk or XPG4 awk?

The grep command above should work, as such. The dash between = and ( in the command you tried seems misplaced; does it help if you take it out? How exactly is the result wrong?
Reply With Quote
  #11 (permalink)  
Old 05-15-2008
Registered User
 

Join Date: May 2008
Posts: 51
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Quote:
grep -v '[=-(]' test.txt
you mean this?

my dashes are not at the first position, in fact it's a certain distance away from the 1st position of the line, having some spaces in between


when i do that command above, it still doesn't remove the dashes, that's all
Reply With Quote
  #12 (permalink)  
Old 05-15-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,253
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
That command should remove any line which contains an equals sign, or an opening parenthesis; the dash you put between also causes it to remove all lines which contain a character whose ASCII code falls between those two, in theory; however, ( comes before = in ASCII so I guess it doesn't really change anything (but could also be the reason you're not getting it to work). Take out the dash and try again? Or move it first or last in the class, like

Code:
grep -v '[-=(]' file

Last edited by era; 05-15-2008 at 11:48 PM. Reason: Or move to beginning or end of class
Reply With Quote
  #13 (permalink)  
Old 05-16-2008
Registered User
 

Join Date: May 2008
Posts: 51
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
thanks era, your method works however.


erm, i got another question though

Quote:
xxx 254 xx 40 HC M U02 25 6 4 0
*space* xx 20 GP H U02 27 3 1 0
*space* xx 20 GP U U02 27 3 1 0
*space* xx 40 HC X U02 25 4 3 0
*space* xx 40 HC U U02 25 6 1 0
*space* xx 20 GP L U02 27 3 1 0
the file indentation for that part is actually like that as of above (well almost, the xx is align with the xx). However, different files has different number of line for that.
However, after the data is done showing, the next line will always be a empty space (or "\n" if what you guys call it)

so how do I extract those data and ignore the 'x254'?
Reply With Quote
  #14 (permalink)  
Old 05-16-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,253
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Different question, different thread. Also try to explain it better. "Before" and "after" samples are often instructive.
Reply With Quote
  #15 (permalink)  
Old 05-16-2008
Registered User
 

Join Date: May 2008
Posts: 51
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
oh ok, I go create another thread
Reply With Quote
Google UNIX.COM
Reply

Tags
solaris

Thread Tools
Display Modes


The 50 most popular UNIX and Linux searches.
Google Search Cloud for The UNIX and Linux Forums
"inappropriate ioctl for device" 421 service not available, remote server has closed connection ^m autosys awk trim bash eval bash exec bash for loop boot: cannot open kernel/sparcv9/unix close_wait command copy/move folder in unix curses.h cut command in unix dead.letter find grep find null character in a unix file grep multiple lines grep or grep recursive grep unique inaddr_any inappropriate ioctl for device lynx javascript mailx attachment mget mtime perl array length ping port remove first character from string in k shell replace space by comma , perl script scp recursive segmentation fault(coredump) sftp batch sftp script snoop unix stale nfs file handle syn_sent tar exclude unix