Visit Our UNIX and Linux User Community


Combine multiple sed


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Combine multiple sed
# 1  
Old 08-29-2013
Combine multiple sed

Would like to convert it to one line

Code:
   sed -i -e '/./,$!d' term1.txt
   sed -i '2d' term1.txt
   sed -i '/^$/Q' term1.txt
   cat term1.txt>> test1.txt

Appreciate if someone could point out the error
Code:
sed -i -e '/./,$!d' -e '2d' -e '/^$/Q'  term1.txt
cat term1.txt>> $test1.txt

---------- Post updated at 02:57 PM ---------- Previous update was at 02:44 PM ----------

On similar lines would like to combine
Code:
cat j| sed 's/^[ \t]*//;s/[ \t]*$//' > j1
cut -f1 -d ' ' jout > jout2
grep -v "at" jout2 > jout3
grep -v "bt" jout3 > jout4
grep  "_box" jout4 > jout4box
grep -v "_box" jout4 > jout4cmd


Last edited by Scott; 08-29-2013 at 07:55 PM.. Reason: Code tags not Icode tags...
# 2  
Old 08-29-2013
Please use code tags as required by forum rules!

What error do you encounter?
# 3  
Old 08-29-2013
No error but the results are nt the same.

---------- Post updated at 03:59 PM ---------- Previous update was at 03:57 PM ----------

I have been able to combine a few :
Code:
cat j| sed 's/^[ \t]*//;s/[ \t]*$//'|cut -f1 -d ' ' > j2
grep -v "ar" j2|grep -v "bi"|grep  "_box" >  jout4box
grep -v "ar" j2|grep -v "bi"|grep -v "_box" > jobsout4cmd

---------- Post updated at 04:01 PM ---------- Previous update was at 03:59 PM ----------

I think the first sed should include the file name and the last one should direct out the file

---------- Post updated at 04:09 PM ---------- Previous update was at 04:01 PM ----------

Why is this not working

Code:
sed -e '/./,$!d' -e '2d' -e '/^$/Q' <  term1.txt > test.txt

---------- Post updated at 04:36 PM ---------- Previous update was at 04:09 PM ----------

the problem is with the '2d'....I am still looking into it

Last edited by Scott; 08-29-2013 at 07:55 PM.. Reason: Code tags not Icode tags...
# 4  
Old 08-29-2013
Please wrap code lines in "code" tags (not "ICODE" tags)!
You can replace cat j| by the more efficient <j (not supported by C-shells).
You can replace grep -v "ar" j2|grep -v "bi" by the more efficient egrep -v "ar|bi" j2.
The
Code:
sed -e '/./,$!d' -e '2d' -e '/^$/Q' <  term1.txt > test.txt

works for me.
Do you get an error?
# 5  
Old 08-29-2013
The objective of 2d is to delete the second line after the first sed deletes all the blank lines at the top. The third sed deletes all lines after it encounters a blank line. The first sed and the third sed are working

the file looks like
Code:
<blank>
<blank>
abc
<blank>
text text
text
 
text not req something
text not req 
text nt req

out put required
Code:
text
text
text


Last edited by Scott; 08-29-2013 at 07:56 PM.. Reason: Code tags
# 6  
Old 08-30-2013
The difference is that the independent commands each work on a modified file, while the combined commands work on the same line of the file.

If you'd describe what you want to achieve, we'd be able to help you. Please explain in detail, and post sample in- and outputs. Your output above definitely cannot be derived from the input you gave with the commands you gave.
# 7  
Old 08-30-2013
The deletion of the initial empty lines does not change the line numbers. The 2d is the 2nd (already deleted) line.
That means the current sed scripts need two sed. Which can be connected by a pipe:
Code:
sed '/./,$!d' < term1.txt | sed '2d; /^$/Q' > test.txt

---------- Post updated at 04:28 PM ---------- Previous update was at 04:08 PM ----------

PS: please wrap your code in [code] tags! (At the top of the Wiki editor)
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #205
Difficulty: Easy
Routing Information Protocol (RIP) runs over Transmission Control Protocol (TCP).
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combine logs span across multiple lines

Hi All, I am having a log file ERROR 2016-12-08 10:22:23.542 some data **** some data****** **** some data****** **** some data****** DEBUG 2016-12-08 10:23:23.542 some data **** some data****** **** some data****** **** some data****** when i grep the log file with ERROR am getting... (3 Replies)
Discussion started by: mohanalakshmi
3 Replies

2. Shell Programming and Scripting

Combine multiple commands

I have the following sh-script: konsole -T todo -e vi todo.txt & konsole -T window1 -e ssh user@server & konsole -T window2 -e ssh user@server2 -e cd directory & The first two lines are working fine. The first opens a txt-file, the second opens a ssh-connection. The third line... (6 Replies)
Discussion started by: andre666
6 Replies

3. Shell Programming and Scripting

Csh - how to combine multiple commands in one line

Hey everyone, I am working in an environment where the different users can use ksh or csh. My situation is that I need the same result with one single command line. I am searching for the real path the file is in. My ksh input and output ts2:ts2adm> cd $(dirname $(which sapcontrol)); pwd -P... (2 Replies)
Discussion started by: h1kelds
2 Replies

4. Shell Programming and Scripting

Combine multiple awk commands

Hi Team, I am getting input like below $ ps -ef | grep pmon | grep -v asm | grep -v grep oracle 3246 1 0 00:03 ? 00:00:01 ora_pmon_racora1 oracle 4367 1 0 00:03 ? 00:00:01 ora_pmon_test1 oracle 6893 1 0 00:03 ? 00:00:01 ora_pmon_gipora1... (6 Replies)
Discussion started by: kamauv234
6 Replies

5. Shell Programming and Scripting

Combine columns from multiple files

Can anybody help on the script to combine/concatenate columns from multiple files input1 4 135 5 185 6 85 11 30 16 72 17 30 21 52 22 76 input2 2 50 4 50 6 33 8 62 10 25 12 46 14 42 15 46output (2 Replies)
Discussion started by: sdf
2 Replies

6. Emergency UNIX and Linux Support

Combine multiple Files into one big file

Hi Ppl, I have a requirement like i will be getting files of huge size daily and if the file size is so huge ,the files will be split into many parts and sent.The first file will have the header details followed by detail records and the consecutive files will have detail records and the last... (11 Replies)
Discussion started by: ganesh_248
11 Replies

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

8. Shell Programming and Scripting

want to combine multiple file into one

Below are the list of files I have I want to consolidate the monthly log in the one file Eg : all the july log to be moved to log_july_full.txt inside the script Path : /home/user/data/log/ Jun 6 04:08 data_log-2010.05.30-10:04:08.txt Jun 13 01:38 data_log-2010.06.06-10:04:08.txt... (3 Replies)
Discussion started by: mail2sant
3 Replies

9. Shell Programming and Scripting

Combine multiple columns from multiple files

Hi there, I was wondering if someone can help me with this. I am trying the combine multiple columns from multiple files into one file. Example file 1: c0t0d0 c0t2d0 # hostname vgname c0t0d1 c0t2d1 # hostname vgname c0t0d2 c0t2d2 # hostname vgname c0t1d0 c0t3d0 # hostname vgname1... (5 Replies)
Discussion started by: martva
5 Replies

10. Shell Programming and Scripting

combine multiple .xl file

Hi Friends, Is it possible in Unix ? The requirement is ============= Create a unix shellscript that combines multiple excel files into one. Note : it is possible for data files.but the requirement is for excel file (4 Replies)
Discussion started by: bikas_jena
4 Replies

Featured Tech Videos