sed split string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed split string
# 1  
Old 07-21-2018
sed split string

Greetings,
i have a string that looks like
Code:
Network "123" "ABC"

i need to make it look like:
Code:
Network "123"
Network "ABC"

Help please?
Thanks again
Moderator's Comments:
Mod Comment Please use CODE tags when displaying sample input, sample output, and code segments (as required by forum rules).

Last edited by Don Cragun; 07-21-2018 at 09:42 PM.. Reason: Add CODE tags.
# 2  
Old 07-21-2018
Hello hoyanet,

Could you please try following and let me know if this helps you.

Code:
 awk '{for(i=2;i<=NF;i++){print $1,$i}}'  Input_file

Thanks,
R. Singh
# 3  
Old 07-22-2018
Quote:
Originally Posted by hoyanet
Greetings,
i have a string that looks like
Code:
Network "123" "ABC"

i need to make it look like:
Code:
Network "123"
Network "ABC"

Help please?
Thanks again
Moderator's Comments:
Mod Comment Please use CODE tags when displaying sample input, sample output, and code segments (as required by forum rules).
Is this a homework assignment? Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

If you did not post homework, please explain the company you work for and the nature of the problem you are working on. Please also tell us what operating system and shell you're using (which should be done in every thread you start) and show us what you have tried to do to solve the problem on your own. It would also help if you explain where you're stuck. And, is this string in a shell variable? Is this string in a file? If you had a string that contained:
Code:
server '123' server "456" text "789"

what output would you want? Giving us a single line sample containing three words and saying you want two lines of output with two words each and no explanation of the reasoning behind that transformation leaves a lot of guessing to be done with no real clues as to what you're really trying to do.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using sed to split hex string

Hi, I'm looking to split the following hex string into rows of four elements. I've tried the following but it doesn't seem to work. How can I tell sed to match based on a pair of number(s) and letter(s), and add a newline every 4 pairs? In addition, I need to add another newline after every... (5 Replies)
Discussion started by: sand1234
5 Replies

2. Shell Programming and Scripting

Need to split a string

Hi, We have a SunOS 5.10 Generic_142900-13 sun4v sparc SUNW,T5240. I'm trying to find a way to split a string into 2 variables. Ex: parm1="192.168.1.101/parent/child" What I need to do is split the string above into: host="192.168.1.101" location="parent/child" I saw the... (3 Replies)
Discussion started by: adshocker
3 Replies

3. Shell Programming and Scripting

split string using sed, perl

How can I split following input into stwo strings: Input: 1^~^2^~^3^~^4^~^5^~^6^~^7^~^8^~^9 Output: $string1 = 1^~^2^~^ $string2 = 3^~^4^~^5^~^6^~^7^~^8^~^9 Note: the length of string may vary, say upto 15. String 1 will contain only first two. string2 will contain... (10 Replies)
Discussion started by: som.nitk
10 Replies

4. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

5. Shell Programming and Scripting

split string

I am trying to get some data from a file and print it on the same line. I have a script that gets the body of emails and display it, but i want it to display each emails body in one line no matter how big it is. eg insted of this email1: bla bla bla bla bla bla bal email2: bla bla bla... (7 Replies)
Discussion started by: maddog21
7 Replies

6. Shell Programming and Scripting

Split string

Hi, can we split a number like this.. if i have something like 85743975945738, can it be converted as 8574-3975-945738 in ksh shell using single command... Thanks! (5 Replies)
Discussion started by: nram_krishna@ya
5 Replies

7. Shell Programming and Scripting

split the string

I need to split the string msu1_2 It should be generic for any string of the form msu<digits>_<digits> so that i get $X =1 and $Y = 2 Please help Thanks (5 Replies)
Discussion started by: asth
5 Replies

8. Shell Programming and Scripting

Split A String

Hi, I am new to scripting and need help splitting a string using space as the delimiter. How can I do that? I want the result to be stored in an Array. I tried using set -A arr $(echo $FILE) echo $arr The result of the above was ''. Thanks. (2 Replies)
Discussion started by: newbie187
2 Replies

9. Shell Programming and Scripting

split string help

could anyone help in running split cmd split("String1,outputArray,"delimiter); with sample script?. for eg i have abc-def-ghi-sdf- my ultimate aim of asking this is i have a string containing hypens, i want to get the string before last n(2) Hypens (4 Replies)
Discussion started by: senthilk615
4 Replies

10. Shell Programming and Scripting

split a string

Hi I have a script that loops though lines of a file and reads each line in to a variable ($LINE). I want to look at the line and split it into it's constituent parts. e.g. a line might be "This is a string" I want to then have variables set to each element thus: A=This B=is C=a... (3 Replies)
Discussion started by: gazingdown
3 Replies
Login or Register to Ask a Question