Adding a character


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Adding a character
# 1  
Old 05-26-2009
Adding a character

Hi,

I cant seem to figure out how I add a character to an existing one. Heres my problem.

So I have a line that looks like this:

>56
584848392394958586858484849393

What I want to do is add Num in front of the 56. So basically I want to recognize the > and add Num in front of the number.

I guess the same scenario would be to add Num to a column.

So I have a column that looks like this:

56
54
43

What what I want to do is add Num to all of them, so it will look like this:

Num56
Num54
Num43

Thanks
# 2  
Old 05-26-2009
that can be done in many ways simpler to uae awk
Code:
awk '/^>/{gsub(">","NUM")}{print}' filename

# 3  
Old 05-26-2009
I forgot something..

Hey that command worked but I made a mistake. Sorry

So want it to add Num in front of the number but also keep the >

So the final output would look like this

>Num56
4757474834848
# 4  
Old 05-26-2009
then use sed its more easy
Code:
sed 's/^\(>\)\([0-9]*\)/\1num\2/g' filename

# 5  
Old 05-26-2009
thank you!

works like a charm! Smilie

-----Post Update-----

What if I wanted to add Num to every row on a column:

So lets say my column looks like this

56
45
45
43
23
45

I want to add Num in front of all the numbers for column 1.

Num56
Num45
Num45
Num43
Num23
Num45

thanks
# 6  
Old 05-26-2009
Quote:
Originally Posted by kylle345
I want to add Num in front of all the numbers for column 1.

Num56
Num45
Num45
Num43
Num23
Num45
the common way to add something in front of a line is to print them out. pseudocode:
Code:
for line in file
  print "num" , line

you can use awk, bash's while read loop etc to iterate files.
# 7  
Old 05-26-2009
common give it a try refer awk man page
if not possible revert back we will definately help you..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding a character

Hello experts. I trying to achieve 2 things here. I'm trying to convert all of the host names to lower case and add an "m" to each hostname. Can anyone provide some guidance on what I can do? Your input is greatly valued! Here are the desired results: 1. read the host name from a file. 2.... (8 Replies)
Discussion started by: david_tech
8 Replies

2. Shell Programming and Scripting

Adding end of line character in the last record

Need to add end of line character to last record in a fixed width file. When i take the record length of each line, for all the records it gives example like 200 except the last line as 199. Due to this my other script fails. Please help me on this. (4 Replies)
Discussion started by: Amrutha24
4 Replies

3. Shell Programming and Scripting

Adding new line character

Hi All, i am taking end of records using tail command got the out is "END OF FILE. ROW COUNT: 10" and record count in the file is 3. while append the both data into test2.txt file,it's append like END OF FILE. ROW COUNT: 108 my output should be in the test2.txt file END OF FILE. ROW... (9 Replies)
Discussion started by: bmk
9 Replies

4. UNIX for Dummies Questions & Answers

Adding space after character using sed?

dears i have the data below, i want a command ( i think it should be sed) that add a space after the seconds as below : Jun 24 22:28:18966568406148@ Jun 24 05:47:35966555747744@ Jun 24 05:47:53966560825239@ Jun 24 06:07:52966541147164@ Jun 24 15:49:55966566478883@ thanks... (5 Replies)
Discussion started by: thehero
5 Replies

5. Shell Programming and Scripting

sort file adding extra character

HI all i have this script : #!/bin/bash sort /usr/tmp/"REPORT"$1 -o \ /usr/tmp/"SREPORT"$1 -k 1,7 -S 150 end of script now i'm doing this command : ls -lsgt *REPORT* 4 -rw-r--r-- 300 Sep 16 REPORT54784 4 -rw-r--r-- 301 Sep 16 SREPORT54784 as you can see the sorted file... (5 Replies)
Discussion started by: naamas03
5 Replies

6. Shell Programming and Scripting

Adding a special character at the end of the line

I used following to add * at the end of the line in file1. It adds * at the end but has a space before it for some lines but some other lines it adds exactly after the last character. How do I take out the space ? sed 's/$/*/' file1 > file2 example: contents of file1 : ... (2 Replies)
Discussion started by: pitagi
2 Replies

7. Shell Programming and Scripting

adding a character in front of a line

Hi everyon, I am trying to search for a pattern in a file and add "//" to the begining of the file. lets say i want to comment out a line from my codes. the line that should be commented out contains the word "reset". i need to search for the word "reset" and comment out that specific line. is... (5 Replies)
Discussion started by: ROOZ
5 Replies

8. Shell Programming and Scripting

Adding character to spaces in a table

Hi All, I am trying to get the spaces in the below table to be fill up with a character " - ". For eg, coordinates 0202 is a space but i would want to fill up with " - ". Can anybody help ? Input: 04 D H ... (15 Replies)
Discussion started by: Raynon
15 Replies

9. Shell Programming and Scripting

Adding CTRL-M Character

Hi, I have file generated in HP-UNIX environment (for Example) with the line feed (i.e $): a$ b$ C$ Now, I need to append CTRL-M character at the end of each line, but the last line of the file should not have both CTRL-M and Line Feed (i.e ^M and $). The file should look like: a^M$ b^M$... (2 Replies)
Discussion started by: mohan.nadaraja
2 Replies
Login or Register to Ask a Question