Substitution mid pattern?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Substitution mid pattern?
# 1  
Old 03-28-2012
Substitution mid pattern?

Hi there,

I have a file that goes like this:

b_cdbc_db_cd_bcd_aaa-bcd_cd

That type of format, for many lines.

What I want to do is enter a new line character for after the _
I write an expression to find "_...-" fine, but I don't know how to substitute this to be:

"_\naaa-" - where \n is the newline inserted, so graphically:
"_
aaa-"

If this is not possible, is it possible to substitute 1 character into a pattern?
My logic would be to reprint the pattern without the _ and simply print a _ before the pattern.

Please do not just give me an answer, I want to learn how to get the answer too :-)

Thanks,
Max.

Last edited by maximus73; 03-28-2012 at 10:43 AM..
# 2  
Old 03-28-2012
Try using sed

Search man pages for sed.

Code:
 
newvar=`echo ${var} | sed 's/\_/\\n/g'`

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find command fails mid-way during execution

I wish to search for a particular string say "Yellow_Colors" in all files in all folders in the current directory. Below is the command I use: find ./ -type f | xargs grep -i "Yello_Colors"However, my command does not traverse all files and folders and errors out mid-way with the below error... (7 Replies)
Discussion started by: mohtashims
7 Replies

2. Shell Programming and Scripting

sed - pattern match - apply substitution

Greetings Experts, I am on AIX and in process of creating a re-startable script that connects to Oracle and executes the statements. The sample contents of the file1 is CREATE OR REPLACE VIEW DB_V.TAB1 AS SELECT * FROM DB_T.TAB1; .... CREATE OR REPLACE VIEW DB_V.TAB10 AS SELECT * FROM... (9 Replies)
Discussion started by: chill3chee
9 Replies

3. UNIX for Dummies Questions & Answers

How to stop debug in the mid of process?

Hi Gurus, I am debugging a script. it loops filelist. since the list a very long. when debugging, I only can see the last a few lines. is there any way to stop debuger in the mid of process. the command I used for debugging is: ksh -x scriptName Thanks in advance (7 Replies)
Discussion started by: ken6503
7 Replies

4. Shell Programming and Scripting

sed pattern substitution issue?

Hello everyone ... I'm going crazy, I hope some of you can help me ... I have to replace a line in a crontab like this: 5 2 * * 2 root backupdat with this: 5 5 * * 3 root backupdat the command I use is the following: sed -i.bak -e 's/5 2 * * 2 root backupdat/5 5 * * 3 root... (4 Replies)
Discussion started by: ionral
4 Replies

5. Web Development

every hour and 24hour mid night cron job

I have 2 pages writing in php, and i want cron job to run the first page 'every hour' and the second page every '24hours in other words mid night'. am using cPanel i put this code on a text file 0 * * * * /home/axe/public_html/admin/viewmemstat.php 1>/dev/null 2>&1 and on the 'Command... (5 Replies)
Discussion started by: francis123
5 Replies

6. Shell Programming and Scripting

Perl:string substitution Pattern: ='abc...',

Hi friends, I want to substitute "a ='....'," with ":" in everywhere in a string using Perl. Details: ---------- my $str= " c1='fgfasfgasggfgff.,akhkhahha', c2='bbbn', c3='hg5 sh' "; Required o/p: $str= " c1:c2:c3 " I tried as below: $str=~ s/=\'.*\',/:/g ; print "str=... (14 Replies)
Discussion started by: Niroj
14 Replies

7. Shell Programming and Scripting

pattern match and substitution, can you help?

pattern match and substitution, can you help? file named test.txt I want to replace all the words Event with the word Fatal in all lines containing the word ERR - but I also want to keep the output of the other lines not matching ERR Test.txt: Event 13 INF egegegege Event 14 INF... (4 Replies)
Discussion started by: frustrated1
4 Replies

8. UNIX for Dummies Questions & Answers

vi/vim : complex pattern substitution

I use vim. I have a lot of SQL queries to write, and am hoping there is some wild command I can use in vim to make this simpler. From a file that is a list of fields, like the excerpt, for example: orderdetail.ccntyfips orderdetail.citemord orderdetail.coffdetid I want to go to this: ... (2 Replies)
Discussion started by: c444l
2 Replies

9. UNIX for Dummies Questions & Answers

Dummie: How do I get variables mid program

I'm writing a simple program in unix and was wondering how mid switch I can run a program and get someone to enter variables for it i.e.: #!/bin/csh -f echo "If you wish to do v press v" echo "If you wish to compile press c" echo "If you wish to add an entry press a" echo "If you wish to... (1 Reply)
Discussion started by: RichardB
1 Replies
Login or Register to Ask a Question