Replace First Column and First Row Data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace First Column and First Row Data
# 1  
Old 10-27-2015
Replace First Column and First Row Data

HI Guys,

I just want to replace data for First Column and Row Cell(1,1)

Input :-
Code:
Hello	A	B	C
X	1	2	3
Y	4	5	6
Z	7	8	9

Output:-

Code:
Byee	A	B	C
X	1	2	3
Y	4	5	6
Z	7	8	9

From Hello to Byee .....And The Each file have Different String.
# 2  
Old 10-27-2015
Hello pareshkp,

Could you please try following and let me know if this helps.
Code:
awk '(NR==1 && $1=="Hello"){sub("Hello","Byee",$0);} 1' Input_file

Output will be as follows.
Code:
Byee A B  C
X 1 2 3
Y 4 5 6
Z 7 8 9

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 10-27-2015
Thanks ... But the Hello String will change in all files.
Do we have any other idea

---------- Post updated at 09:43 AM ---------- Previous update was at 09:36 AM ----------

Got it Thanks

Code:
nawk '(NR==1){sub($1,"Byee",$0);} 1'

# 4  
Old 10-27-2015
Hello PareshKP,

I don't think so code posted in POST#2 will substitute all the strings Hello, in a single file, here is an example for same.
Code:
cat Input_file
Hello A B C
X 1 2 3
Hello 4 5 6
Z 7 8 9

Then same code as POST#2 following will be the output.
Code:
awk '(NR==1 && $1=="Hello"){sub("Hello","Byee",$0);} 1'  Input_file
Byee A B  C
X 1 2 3
Hello 4 5 6
Z 7 8 9

Please do let us know if your requirement if a little different, in my code only it is looking for string Hello if you want to change any thing in $1 with Byee then your code is correct too except one change, where if you have multiple file then following may help you in same. Change NR with FNR as FNR variable will be RESET whenever there is new file is being read, on the other hand NR's value will be keep increasing till the last file read.
Code:
awk '(FNR==1){sub($1,"Byee",$0);} 1'  Input_file Input_file1

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Column to Row Data.

HI Guys, I have below Input :- X L1 5 Y L1 10 Z L1 15 X L2 20 Y L2 12 Z L2 15 X L3 100 Y L3 Z L3 300 Output:- ID L1 L2 L3 X 5 10 15 Y 20 12 15 Z 100 Null 300 (11 Replies)
Discussion started by: pareshkp
11 Replies

2. Shell Programming and Scripting

Convert Data from Column to Row

Hi FileA.txt E_TIM 16, ETE 15, EOND 26, EEC 81, E_1 un, E_2 un, E_3 un, E_4 284, E_TIM 17, ETE 15, EOND 29, EEC 82, E_1 un, E_2 un, E_3 un, E_4 249, (6 Replies)
Discussion started by: asavaliya
6 Replies

3. UNIX for Advanced & Expert Users

Convert column data to row data using shell script

Hi, I want to convert a 3-column data to 3-row data using shell script. Any suggestion in this regard is highly appreciated. Thanks. (4 Replies)
Discussion started by: sktkpl
4 Replies

4. Shell Programming and Scripting

Sort data from column to row

Hi, I need somebody's help with sorting data with awk. I've got a file: 10 aaa 4584 12 bbb 6138 20 ccc 4417 21 ddd 7796 10 eee 7484 12 fff ... (5 Replies)
Discussion started by: killerbee
5 Replies

5. Shell Programming and Scripting

Replace last row of a column in bash/awk/sed

Hi, I've got a file with 3 columns which ends like this: ... 1234 345 1400 5287 733 1400 8472 874 1400 9317 726 1400 I want to replace the last row of the last column with the value 0. So my new file will end: ... 1234 345 1400 5287 733 1400 8472 874 1400 9317 726 ... (5 Replies)
Discussion started by: jhunter87
5 Replies

6. Shell Programming and Scripting

Moving data from a specified column/row to another column/row

Hello, I have an input file like the following: 11_3_4 2_1_35 3_15__ _16989 Where '_' is a space. The data is in a table. Is there a way for the program to prompt the user for x1,y1 and x2,y2, where x1,y1 is the desired number (for example x=6 y=4 is a value of 4) and move to a desired spot... (2 Replies)
Discussion started by: jl487
2 Replies

7. Shell Programming and Scripting

Find and replace duplicate column values in a row

I have file which as 12 columns and values like this 1,2,3,4,5 a,b,c,d,e b,c,a,e,f a,b,e,a,h if you see the first column has duplicate values, I need to identify (print it to console) the duplicate value (which is 'a') and also remove duplicate values like below. I could be in two... (5 Replies)
Discussion started by: nuthalapati
5 Replies

8. Shell Programming and Scripting

row to column and position data in to fixed column width

Dear friends, Below is my program and current output. I wish to have 3 or 4 column output in order to accomodate in single page. i do have subsequent command to process after user enter the number. Program COUNT=1 for MYDIR in `ls /` do VOBS=${MYDIR} echo "${COUNT}. ${MYDIR}" ... (4 Replies)
Discussion started by: baluchen
4 Replies

9. Shell Programming and Scripting

Convert row data to column data

Hi Guys, I have a file as follows: a 1 b 786 c 90709 d 99 a 9875 b 989 c 887 d 111 I want: a 1 9875 b 786 989 (3 Replies)
Discussion started by: npatwardhan
3 Replies

10. Shell Programming and Scripting

Move data from Column to Row

Hi all, I have a file with several columns of data, eg: A B C D 1 2 5 1 2 2 2 2 8 4 4 4 4 2 3 4 10 9 4 4 9 7 1 2 I need to get the values from, say, column B and place them into a string separated by a semicolon, eg: 2;2;4;2;9;7 Does... (4 Replies)
Discussion started by: danhodges99
4 Replies
Login or Register to Ask a Question