combine 2 awks statement into 1 liner


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting combine 2 awks statement into 1 liner
# 1  
Old 03-30-2010
Question combine 2 awks statement into 1 liner

Using these 2 comands to concatenate both outputs into single file:

Code:
cat testdata | awk 'BEGIN { FS="\n"; RS=""; } /<pattern1>/ {print}' > testdata1
cat testdata| awk '/<pattern2>/,EOF' >> testdata1

is it possible to combine both "awk" into 1-liner?

pls advise and thanks in advance.

Last edited by Franklin52; 03-30-2010 at 03:14 AM.. Reason: Please use code tags!
# 2  
Old 03-30-2010
what are you trying to do?
Code:
awk 'BEGIN { FS="\n"; RS=""; } /<pattern1>/ || /<pattern2>/' testdata > testdata1

# 3  
Old 03-30-2010
testdata file:
Code:
<start of file>
<some data>
<pattern1>

<error data>

<error data>
<pattern2>
...
<some data>
<eof>
<some

- trying to remove data between <pattern1> and <pattern2>

---------- Post updated at 01:31 AM ---------- Previous update was at 01:22 AM ----------

will this work?
Code:
sed -n '/pattern1/,/pattern2/d' testdata


Last edited by Franklin52; 03-30-2010 at 04:10 AM.. Reason: Please use code tags!
# 4  
Old 03-30-2010
Yes, why don't you try it!!!
# 5  
Old 03-30-2010
Hello, ux4me:

-n = don't print each line by default
d = delete line

That sed will never print anything. It stands a chance however if you remove -n. As malcomex999 suggested, give it a try Smilie

Regards,
Alister
# 6  
Old 04-05-2010
works fine now.. thanks again for the quick help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

2. Shell Programming and Scripting

Combine awk statement into one

awk '{a=$0} END {while (NR) print a}' mail.log | awk '/Feb 2/ {print ;exit;}' first, can this code be combined into one? what i want this code to do is output every single line it finds up until the last occurrence of "Feb 2". right now, this code simply outputs one line, and aborts. ... (12 Replies)
Discussion started by: SkySmart
12 Replies

3. Shell Programming and Scripting

Combine these two into one liner awk?

ignore the simplicity of the foo file, my actual file is much more hardcore but this should give you the jist of it. need to combine the two awks into one liner. essentially, need to return the value of one particular field in a file that has multiple comma separated fields. thanks guys cat foo... (1 Reply)
Discussion started by: jack.bauer
1 Replies

4. Shell Programming and Scripting

Need help with shell script using multiple awks

I have a command lline script that works perfectly. cat <some_filename> | awk '$9 == 200' | awk '$10 == 10623720' | awk -F\" '{print $6}' | sort | uniq -c | sort -r I want to put this in a shell script so that we do this for multiple files(all read from a file list) and write each output to... (5 Replies)
Discussion started by: ampak
5 Replies

5. Shell Programming and Scripting

combine lines from two files based on an if statement

I'm rather new to programming, and am attempting to combine lines from 2 files in a way that is way beyond my expertise - any help would be appreciated! I need to take a file (file1) and add columns to it from another file (file2). However, a line from file2 should only be added to a given line... (3 Replies)
Discussion started by: Cheri
3 Replies

6. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

7. Shell Programming and Scripting

help one liner...

Hi I have a log data that shows chunks of data like this: thisis example test, this is example test, this is example test thisis example test, this is example test, this is example test thisis example test, this is example test, this is example test thisis example test, this is example test,... (2 Replies)
Discussion started by: erick_tuk
2 Replies

8. Shell Programming and Scripting

combine multiple finds into 1-liner

How to combine 3 find statements into 1-liner? find statements: cd ${dir1} ; find . ! -name . -prune -type f | xargs file | grep -i ascii | cut -f1 -d: | xargs grep -l "${searchtxt}" cd ${dir2} ; find . ! -name . -prune -type f | xargs file | grep -i ascii | cut -f1 -d: | xargs grep -l... (4 Replies)
Discussion started by: ux4me
4 Replies

9. Shell Programming and Scripting

Help Needed with 1 liner AWK statement

Greetings, I attempting to create a line statement that will do the following: 1. Read the input file 2. Extract lines containing certain keep words 3. Print the lines in a tabular format (CSV) Help is what I have so far: # cat text.tx | egrep -i -e "(Check Name) | (Risk Level) |... (6 Replies)
Discussion started by: jroberson
6 Replies

10. Shell Programming and Scripting

running simultaneous awks

Hello, I have an awk command that searches and replaces. I have multiple searches, but I do not want to do them one after the other. Is there a way in awk to run search/replace at the same time. thanks, (3 Replies)
Discussion started by: ctcuser
3 Replies
Login or Register to Ask a Question