changing files content with sed or awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting changing files content with sed or awk
# 1  
Old 06-30-2011
changing files content with sed or awk

Hi,
Example File:
Code:
(jumped,
bumped,
)
how to
jumped,
FROM tree;
EXIT

I have some hundreads of files like this with the different words and I want to remove the comma before the bracket and also I have to remove the comma before FROM word.

I am trying to use this command :
Code:
awk ' BEGIN{RS=")"} {print substr($0,1,length($0)-2) ")" }'

but its removing comma before bracket and also its inserting another bracket at the end after the EXIT.

Thanks in advance.
RS

Thanks in advance.

Last edited by Franklin52; 06-30-2011 at 12:08 PM.. Reason: Please use code tags, thank you
# 2  
Old 06-30-2011
Code:
sed 's/,FROM/FROM/g'


Last edited by Franklin52; 06-30-2011 at 12:08 PM.. Reason: Please use code tags, thank you
# 3  
Old 06-30-2011
sorry.. this command is not working.
Code:
sed 's/,from/from/g'

because after comma there is a new line "ENTER" character and the command is not recongnizing.

RS

Last edited by Franklin52; 06-30-2011 at 12:08 PM.. Reason: Please use code tags, thank you
# 4  
Old 06-30-2011
hi try this.
Code:
# sed '/^[^(]*,$/N;s/\(.*\),\(\n)\|\nFROM.*\)/\1\2/' file
(jumped,
bumped
)
how to
jumped
FROM tree;
EXIT

regards
ygemici
# 5  
Old 06-30-2011
Code:
awk '{if(/^\)/ || /^FROM/){sub(",","",a);print a;a=$0;next;}else{if(a){print a};a=$0}} END{print a}' FILENAME

# 6  
Old 06-30-2011
Thanks a lot everyone.

I dont know some how sed command is not working but above awk command is working good.

Once again thanks a lot everyone.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sed, awk or another bash command to modify string with the content of another file

Hello everybody, I would like modify some strings using sed or another command line with the content file. For example: - {fqdn: "server-01" , ip: "server-01"} - {fqdn: "server-02" , ip: "server-02"} - {fqdn: "server-03" , ip: "server-03"} - {fqdn: "server-04" , ip: "server-04"} My... (4 Replies)
Discussion started by: dco
4 Replies

2. Shell Programming and Scripting

Sorting content between match pattern and move on with awk and sed

S 0.0 0.0 (reg, inst050) k e f d c S 0.0 0.0 (mux, m030) k g r s x v S 0.0 0.0 (reg, inst020) q s n m (12 Replies)
Discussion started by: ctphua
12 Replies

3. Shell Programming and Scripting

sed/awk changing values

Can somebody help me out and provide me with a SED or AWK solution that converts TO_DATE CLAUSE -> TIMESTAMP I need to keep the PARTION value (HISTORY_20110417) and DATE/TIME value (2011-04-18 00:00:00) the same for every line PARTITION HISTORY_20110417 VALUES LESS THAN (TO_DATE('... (3 Replies)
Discussion started by: BeefStu
3 Replies

4. Shell Programming and Scripting

How can i delete the content between all the occurences of two strings using sed or awk command

Hi. I have to delete the content between all the occurrences of the xml tags in a single file. For example: * The tags <script>.....................</script> occurs more than once in the same file. * It follows tagging rules meaning a start tag will be followed by an end tag. Will not have... (9 Replies)
Discussion started by: satheeshkumar
9 Replies

5. UNIX for Dummies Questions & Answers

sed insert content of file.txt to multi files

Ive this sed & find command find /home/www/ -name footer.php -exec sed -i 's/<\/body>/file.txt\n<\/body>/' what I need to place content of file.txt before </body> in all footer.php files file.txt content is google analytic script which is like 7 lines any help to adjust my command to... (2 Replies)
Discussion started by: xmoe
2 Replies

6. UNIX for Dummies Questions & Answers

Changing Text with sed or awk

I'm changing some html code on multiple web pages and I need to match particular phrases but keep some text within each phrase. E.G. I need to change this line: <DIV id="heading">Description:</DIV> into <span class="hlred">Description:</span><br /> The text "Description:" may... (2 Replies)
Discussion started by: hal8000
2 Replies

7. Shell Programming and Scripting

Changing one number in all files using awk

Hi I want to change the number 70 mentioned in my file to 76 by using awk. I know how to change all same digits but not one particular number. I have 29 files almost similar to this. One of my files looks like #Input file for 200K NPT molecular dynamics of final 70%XL made from 58.5%... (3 Replies)
Discussion started by: ananyob
3 Replies

8. Shell Programming and Scripting

awk/sed/perl command to delete specific pattern and content above it...

Hi, Below is my input file: Data: 1 Length: 20 Got result. Data: 2 Length: 30 No result. Data: 3 Length: 20 (7 Replies)
Discussion started by: edge_diners
7 Replies

9. Shell Programming and Scripting

sed, awk [TAG]$content[/TAG] How to get var in $content in textfile?

Hello, I got a Qstion. Im posting to a phpbb forum with bash and curl.. i have a text file with the following tags that i post to the forum: $var1 $var2 $var3 How can i with sed or awk put var content from shell script between the ... in the... (7 Replies)
Discussion started by: atmosroll
7 Replies

10. Shell Programming and Scripting

Read a file content with awk and sed

Hello , I have huge file with below content. I need to read the numeric values with in the paranthesis after = sign. Please help me with awk and sed script for it. 11.10.2009 04:02:47 Customer login not found: identifier=(0748502889) prefix=(TEL) serviceCode=(). 11.10.2009 04:03:12... (13 Replies)
Discussion started by: rmv
13 Replies
Login or Register to Ask a Question