Sed/command assistance


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sed/command assistance
# 1  
Old 10-03-2014
Sed/command assistance

Hello all,

I need some help and education creating a script.

Basically I have a file with a list of numbers..
Code:
2125554444
2124445555

I need to put them into a format that looks like this....
Code:
UQ-V8.1,2125554444,hdaudio
UQ-V8.1,2124445555,hdaudio

Any help would be greatly appreciated.


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 10-03-2014 at 09:00 AM.. Reason: code tags
# 2  
Old 10-03-2014
What have you tried so far?

Where is the additional data coming from? Is it just 2 fixed strings?
# 3  
Old 10-03-2014
Quote:
Originally Posted by jay11789
Hello all,

I need some help and education creating a script.

Basically I have a file with a list of numbers..

2125554444
2124445555

I need to put them into a format that looks like this....

UQ-V8.1,2125554444,hdaudio
UQ-V8.1,2124445555,hdaudio

Any help would be greatly appreciated.
Hi Jay11789,

Following may help, also please use code tags while posting code and commands.

Code:
awk -vvar1="UQ-V8.1" -vvar2="hdaudio" '{print var1 OFS $0 OFS var2}' OFS="," Input_file

Output will be as follows.

Code:
UQ-V8.1,2125554444,hdaudio
UQ-V8.1,2124445555,hdaudio

EDIT: Sorry CarloM, seems I was replying when you have asked the question.


Thanks,
R. Singh

Last edited by RavinderSingh13; 10-03-2014 at 09:04 AM.. Reason: Admin Team, please remove my post if needed as CarloM have asked a question to OP.
# 4  
Old 10-03-2014
sed 's/.*/UQ-V8.1,&,hdaudio/' inputfile

regards...

---------- Post updated at 02:09 PM ---------- Previous update was at 02:06 PM ----------

Code:
sed 's/.*/UQ-V8.1,&,hdaudio/' inputfile

regards...
# 5  
Old 10-03-2014
Sorry guys....

I was doing this..

Code:
cat file | sed 's/[[^\t]*/, &/11' | sed 's/^/UQ-V8.1 ,/g' | sed 's/$/hdaudio/g'   > new_file

and the output had spaces....

UQ-V8.1 ,2124445555, hdaudio

---------- Post updated at 08:51 AM ---------- Previous update was at 08:10 AM ----------

Ok, thanks all! I got that going now thanks to your help. However, I have another question..

In this list, I come across a number of lines that I would like to remove. For example,

Code:
UQ-V8.1,2124446666,hdaudio
          UQ-V8.1,2124446667,hdaudio

I have tried doing this....

Code:
grep -v 2124446666

however, Im not having much luck.

Any suggestions?
# 6  
Old 10-03-2014
Guys please respect if someone is asking question on forum about the attempts made towards the thread, here we'll expect thread poster to show us that what actually he/she made an attempt to solve his/her own problem with what he/she learned by following these forums for several years.

It looks to me like some people treating this site as a free programming department. That is not why we volunteer our time here; we want to help them to learn how to write their own code. When they run into problems, we're happy to help them to learn how to get around them.
# 7  
Old 10-03-2014
My apologies, I did post my attempt info, just after my original post.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Assistance required to decode sed search using /1

Hi, I am trying to extract line number (first number), as well as everything from TSVal onwards. 4 1.474005 172.18.124.142 -> 74.125.228.46 TCP 2450940617 74 44021 > https Seq=0 Win=5840 Len=0 MSS=1380 SACK_PERM=1 TSval=2450940617 TSecr=0 WS=64 6 1.488149 172.18.124.142 ->... (1 Reply)
Discussion started by: sand1234
1 Replies

2. Shell Programming and Scripting

sed assistance

Hello everyone. I am trying to replace sprintf(buffer, "{\"id\":1,\"method\":\"mining.update_block\",\"params\":}\n", coinid, blockhash); with sprintf(buffer, "{\"id\":1,\"method\":\"mining.update_block\",\"params\":}\n", coinid, blockhash); this is the code I was trying but is... (9 Replies)
Discussion started by: crombiecrunch
9 Replies

3. UNIX for Dummies Questions & Answers

Sed/command assistance

Hello, I'm attempting to play with sed commands again... I have a file named test1 with numbers...ex:5551234567 I run this sed on the file... cat test1 | sed 's/^/homeDnModify "/g' | sed 's/$/" "" 3/g' >test2 Im hoping it will look like this... homeDnModify "551235" "4567" ""... (5 Replies)
Discussion started by: jay11789
5 Replies

4. Shell Programming and Scripting

sed newbie scripting assistance

Howdy folks, I'm trying to craft a log file summarisation tool for an application that creates a lot of duplicate entries with only a different suffix to indicate point of execution. I thought I'd gotten close but I'm clearly missing something. Here's a genericized version: A text_file... (3 Replies)
Discussion started by: mthespian
3 Replies

5. UNIX for Advanced & Expert Users

Need assistance with sed

Hi All, I need your assistance, I would like to replace all lines beginning with the word "begin" with the below text: Device | IPMB0-A | IPMB0-B Board Address |Sent SentErr %Errr |Sent SentErr ... (10 Replies)
Discussion started by: Dendany83
10 Replies

6. Shell Programming and Scripting

Need assistance with sed

Hi All, I need your assistance, I would like to replace all lines beginning with the word "begin" with the below text: Device | IPMB0-A | IPMB0-B Board Address |Sent SentErr %Errr |Sent SentErr ... (9 Replies)
Discussion started by: Dendany83
9 Replies

7. Shell Programming and Scripting

sed search and replace word assistance...

Hi, I am trying to write a shell script designed to take input line by line by line from a file with a word on each line for editing with sed. Example file: 1.ejverything 2.bllown 3.maikling 4.manegement 5.existjing 6.systems My design currently takes input from the user, and... (2 Replies)
Discussion started by: mkfitzwilliams
2 Replies

8. Shell Programming and Scripting

Need assistance with appending strings using sed and variables

HI, Can't seem to find anything on the forums to fix this. I have a file, one line within this will not have a specific string at the end. I have the string, but need to append it to the specific line which has it missing. I need to use a variable for this, $string - I am using double... (13 Replies)
Discussion started by: mandriver
13 Replies

9. UNIX for Advanced & Expert Users

assistance requested (sed related)

I gotta write a command to change the accounts in /etc/passwd that use a shell other than the bash to bash shell. those accounts that dont use a shell shouldnt get modified. assuming all the shell programs end in sh and other programs dont. and the result should go into /etc/passwd.rev any hint? (4 Replies)
Discussion started by: metalwarrior
4 Replies

10. UNIX for Advanced & Expert Users

need assistance: sed and repeating patterns

hi, I need to write a command with sed to find all the lines in a file that contain patterns of three or more characters that repeat once and put them inside perenthezes. I cannot tell sed what pattern to look for. it should find repeated patterns automatically. example:... (1 Reply)
Discussion started by: metalwarrior
1 Replies
Login or Register to Ask a Question