i am not getting any idea how to do the following with SED cmd


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers i am not getting any idea how to do the following with SED cmd
# 1  
Old 07-25-2009
Question i am not getting any idea how to do the following with SED cmd

hi friends

i am not getting any idea about how to implement the following with the help of SED cmd


1)need a sed command that deletes the first character in each line in a file


2)need sed command that deletes the character before the last character in each line in a file


3)need a sed command that swaps the first and second words in each line in a file



please help me
# 2  
Old 07-25-2009
Give your input file and desired output if it is not a homework (I guess I had the same homework be4)
# 3  
Old 08-03-2009
ok sir i agree with you; but i tried by using the following sed commands

1)$sed 's/^.//' myfile1
2)$sed 's/..$//' myfile1
3)$sed 's/ \([a-z]*\)/ \([a-z]*\)/ \2,\1' myfile1

NOte but i am not getting the required output plz help


my
given input file "myfile1" is as follows

root pts/1 july3109 192.200.200.9
cse1 pts/2 july3109 192.200.200.10
cse2 pts/3 july3109 192.200.200.11
cse3 pts/4 july3108 192.200.200.12


output to be required is (using sed commads):
1) delete the first character in each line of the above input file
2)and deletes the character before the last character in each line of the above file
3)swap the first and 2nd words in the above file
# 4  
Old 08-03-2009
Quote:
Originally Posted by sankar_vitam
ok sir i agree with you; but i tried by using the following sed commands

1)$sed 's/^.//' myfile1
2)$sed 's/..$//' myfile1
3)$sed 's/ \([a-z]*\)/ \([a-z]*\)/ \2,\1' myfile1

NOte but i am not getting the required output plz help


my
given input file "myfile1" is as follows

root pts/1 july3109 192.200.200.9
cse1 pts/2 july3109 192.200.200.10
cse2 pts/3 july3109 192.200.200.11
cse3 pts/4 july3108 192.200.200.12


output to be required is (using sed commads):
1) delete the first character in each line of the above input file
2)and deletes the character before the last character in each line of the above file
3)swap the first and 2nd words in the above file
1. What do you mean by "word"? If you mean strictly alphabetic characters then the first line has the first word as "root" and the second word as "pts", but the second line has the first word as "cse" and the second word as "pts." Is this really what you want? Perhaps you really mean "swap the first and 2nd fields delimted by whitespace."

2. I'm guessing you are deleting the last two characters of the line instead of just the last character. It would help if you posted the output you are getting as well as the additional information other repliers have suggested.

3. Your command to swap words has other problems besides the lack of a definition for what a word is. Do you really want to insert a comma in the output between the swapped words? I don't see that requirement in your list. Also, s command for swapping should have given you a "command garbled" message from sed because you either

a. did not escape the "/" or
b. you have extra characters after the final "/" of the sed command. The form of your 3rd sed command should be the same as the first two.
# 5  
Old 08-21-2009
sed

i am not getting sed
# 6  
Old 08-21-2009
Your 1st command works fine:

[aaaa@xxxx] $ cat file
root pts/1 july3109 192.200.200.9
cse1 pts/2 july3109 192.200.200.10
cse2 pts/3 july3109 192.200.200.11
cse3 pts/4 july3108 192.200.200.12

[aaaa@xxxx] $ sed 's/^.//' file
oot pts/1 july3109 192.200.200.9
se1 pts/2 july3109 192.200.200.10
se2 pts/3 july3109 192.200.200.11
se3 pts/4 july3108 192.200.200.12

Last edited by miltonkeynesguy; 08-24-2009 at 03:12 AM..
# 7  
Old 09-01-2009
sed cmd doubt

Quote:
Originally Posted by ishaancnu20
i am not getting sed




sed fullform is stream editor cmd i want sed instruction(command) for the earlier query
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Embed cmd into sed replacement to have dynamic substitution

Hello, Is it possible to embed the command output to the replacement of sed? Say I need to replace all the blank lines with random strings: input: ACCTTCGTCTTCTGG GCTTGAGATGGTCCA GCAGGGCTAGTGACG GACGAGTCTCTTGAC ACCAAATCAAAGATCand output is: >26aa36d934d44f06d15b3aab4645a602 $(date |... (9 Replies)
Discussion started by: yifangt
9 Replies

2. Shell Programming and Scripting

Perl open(CMD, "cmd |"); buffering problem..

Hello, There's a third-party application's command that shows the application's status like "tail -f verybusy.log". When use the command, the output comes every 1-sec. but when it goes in a script below the output comes every 8-sec...What is the problem and how can I fix it? open(CMD,... (2 Replies)
Discussion started by: Shawn, Lee
2 Replies

3. Shell Programming and Scripting

Unix cmd prompt how to get old cmd run?

Hi, I am using SunOS I want to serch my previous command from unix prompt (like on AIX we can search by ESC -k) how to get in SunOs urgent help require. (10 Replies)
Discussion started by: RahulJoshi
10 Replies

4. Shell Programming and Scripting

sed command works from cmd line to standard output but will not write to file

Hi all .... vexing problem here ... I am using sed to replace some special characters in a .txt file: sed -e 's/_<ED>_/_355_/g;s/_<F3>_/_363_/g;s/_<E1>_/_341_/g' filename.txt This command replaces <ED> with í , <F3> with ó and <E1> with á. When I run the command to standard output, it works... (1 Reply)
Discussion started by: crumplecrap
1 Replies

5. UNIX for Dummies Questions & Answers

sed cmd

write the sed command for swapping the first and 2nd (fields)words in the following file input file cse1 rama 1223 cse2 raju 2453 cse3 sita 3523 i tried with this $sed 's/ \(*\)/ \(*\)/ \2,\1' myfile1 but not getting th required... (4 Replies)
Discussion started by: sankar_vitam
4 Replies

6. UNIX for Advanced & Expert Users

Need some more idea...urgent

Hi friends.. I am using the below command to search few files from many folders which is under one folder.. i mean let say the path is A/B/C...and inside C...i have 1-10 folder... the below command is working fine.... find /A/B/C -name "*.txt" -o -name "*.csv" -o -name "*.TXT" -o -name... (1 Reply)
Discussion started by: sapan123
1 Replies

7. Shell Programming and Scripting

help... no idea what to use

my issue now is i have a txt file containing a list like below i want to create a script that will add a constant text "Find this name" at the start and "at your directory" at the end. every line should be added by phrase at the start and end. Each line of the file should look like "Find... (4 Replies)
Discussion started by: dakid
4 Replies

8. Shell Programming and Scripting

Inserting a carriage rtn in a sed cmd

I suppose this is a silly newbie Q, but I have a set of text I am inserting into a file using a sed cmd and before I insert, I want to ask the sed operation to move to add a carriage return first, and then place my new line. Is there scope within the sed command to do this - i have tried "\n"... (6 Replies)
Discussion started by: sirtrancealot
6 Replies

9. UNIX for Dummies Questions & Answers

man <cmd> >> cmd.txt

I've noticed most of my postings here are because of syntax errors. So I want to begin compiling a large txt file that contains all the "man <cmd>" of the commands I most have problems with. I ran a "man nawk >> nawk.txt" but it included a header/footer on each "page". Anyone know how I'd be... (6 Replies)
Discussion started by: yongho
6 Replies

10. Shell Programming and Scripting

Limitations of awk? Good idea? Bad idea?

Keeping in mind that I'm relatively comfortable with programming in general but very new to unix and korn/bourne shell scripts.. I'm using awk on a CSV file, and then performing calculations and operations on specific fields within specific records. The CSV file I'm working with has about 600... (2 Replies)
Discussion started by: yongho
2 Replies
Login or Register to Ask a Question