Visit Our UNIX and Linux User Community

Shell scripting string manipulation

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell scripting string manipulation
# 1  
Old 02-25-2010
Shell scripting string manipulation


if I have a string delimited by commas how can I put each character on a new line followed by a carriage return, and output this to a filee.g





thanks you
# 2  
Old 02-25-2010
echo "s,t,r,i,n,g" | tr ',' '\n'

# 3  
Old 02-25-2010
Tools I think tr is the better command, but here it is with awk

>echo s,t,r,i,n,g | gawk 'BEGIN {RS=","}{print $1}'

# 4  
Old 02-25-2010
I would use sed, like this:


This simply uses a substitution command to replace each comma with a newline. You would have to store the string in a file first, then feed the file into the sed script, like this:

sed -f sedscript file

Then just delete the file when you're done with it.

Last edited by Ultrix; 02-25-2010 at 10:09 PM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #402
Difficulty: Medium
The term 3D printing originally referred to a powder bed process employing standard and custom inkjet print heads.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert String to an Array using shell scripting in JSON file.

This is the sample json I have pasted here. I want all the IP address strings to be converted into an array. For example "" has to be converted to everywhere in the JSON. There are multiple IPs in a JSON I am pasting one sample object from the JSON. But the IPs already in an Array... (11 Replies)
Discussion started by: vinshas1
11 Replies

2. Shell Programming and Scripting

How can I extract digits at the end of a string in UNIX shell scripting?

How can I extract digits at the end of a string in UNIX shell scripting or perl? cat file.txt abc_d123_4567.txt A246_B789.txt B123cc099.txt a123_B234-012.txt a13.txt What can I do here? Many thanks. cat file.txt | sed "s/.txt$//" | ........ 4567 789 099 012 13 (11 Replies)
Discussion started by: mingch
11 Replies

3. UNIX for Beginners Questions & Answers

Shell Scripting , need to search and replace a string in AIX

Hi Guys, I need to search and replace a string in AIX using variables and should be case insensitive. I am able to search and replace using below command but its not working as case insensitive. cat abc.txt | sed -e 's/$a/$b/g' > abc.txt But i need to perform this with case... (9 Replies)
Discussion started by: mohit_vardhani
9 Replies

4. Shell Programming and Scripting

Stream manipulation in UNIX shell scripting

i have a file something like this : start: 01:00:00 01:30:00 02:30:00 05:30:00 end: 01:13:00 02:00:00 02:40:00 05:45:00 and i want (end - start) total run time in below format: run: 00:13:00 00:30:00 00:10:00 00:15:00 (4 Replies)
Discussion started by: Acme
4 Replies

5. Shell Programming and Scripting

Shell Scripting Date manipulation

Hi Experts, i have date as inputdate=01/01/2013,how to get the previous date from this date and also first day's date of the month. example: inputdate=01/06/2013 previousdate=31/05/2013 firstdate=01/05/2013 how can i get solution to this. my unix is not supporting GNU Dates ... (0 Replies)
Discussion started by: learner24
0 Replies

6. Shell Programming and Scripting

How to convert string into integer in shell scripting?

Hi All, sessionid_remote=$(echo "select odb_sessionid from sysopendb where odb_dbname='syscdr';" | sudo -u cucluster ssh ucbu-aricent-vm93 "source /opt/cisco/connection/lib/connection.profile; $INFORMIXDIR/bin/dbaccess sysmaster@ciscounity") for sid in $sessionid_remote;do if * ]];... (2 Replies)
Discussion started by: deeptis
2 Replies

7. UNIX for Advanced & Expert Users

string manipulation in bash shell

Hi All, I am using a bash shell and want to the following thing. A process sends the following string to my script BACKUP_FAIL_REASON="Failed - Application Dump CDMACA-0:grep: /opt/nortel/ca/data/1245184/sd00/image1/S110907070708HIS... (4 Replies)
Discussion started by: Pkumar Sachin
4 Replies

8. Shell Programming and Scripting

Shell scripting -append a new string

hi all , i am looking for a shell script which looks into a directory of text files and searches for a string(abc123) in all the text files and if that exists add a new line(abc124) in all the *.txt files automatically, or if (abc124) exists add (abc123) can you all please help me. (6 Replies)
Discussion started by: joseph.dmello
6 Replies

9. Shell Programming and Scripting

sed string manipulation in shell script

Hello, I have 1000 of sql queries and i need to push column value in query. e.g. SET INSERT_ID=1 INSERT INTO test (id,name) VALUES ('a'); SET INSERT_ID=2 INSERT INTO test (id,name) VALUES ('b'); SET INSERT_ID=3 INSERT INTO test (id,name) VALUES ('c'); SET INSERT_ID=4 INSERT INTO test... (12 Replies)
Discussion started by: mirfan
12 Replies

10. Shell Programming and Scripting

String comparision in shell scripting

Hi Guys, I am new to scripting I have written a code to compare strings,but I am getting some Exception Code snippet: MODE="D" if ]; then . $file1 fi Error: ./ [[: execute permission denied I have given all Execute permissions to the script(chmod 755... (2 Replies)
Discussion started by: Anji
2 Replies

Featured Tech Videos