Replace string in unix from 10th column onwards

 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications Replace string in unix from 10th column onwards
# 1  
Old 11-20-2009
Network Replace string in unix from 10th column onwards

Hi All,

I need to replace the last 19 bytes of the following string

My_Org_Testing_20090102_231124.txt (Text_Date_Time.txt).

I would like to derive the current time using "date +%Y%m%d_%H%M%S.txt" and replace the last 19 bytes of the above string

I would appreciate if someone could help me on this.

Thanks in advance

Regards,
Rohan
# 2  
Old 11-20-2009
Something like this.
Code:
var=My_Org_Testing_20090102_231124.txt 
echo $var| sed 's/My_Org_Testing_\(.*\)/My_Org_Testing_'$(date +%Y%m%d_%H%M%S.txt)'/

# 3  
Old 11-20-2009
Code:
$ s="My_Org_Testing_20090102_231124.txt"
$ echo ${s%???????????????????}$(date +%Y%m%d_%H%M%S.txt)

# 4  
Old 11-20-2009
Code:
 $ echo "My_Org_Testing_20090102_231124.txt"  | sed "s/.\{19\}$/$(date +%Y%m%d_%H%M%S.txt)/"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search partial string in a file and replace the string - UNIX

I have the below string which i need to compare with a file and replace this string in the file which matches closely. Can anyone help me on this. string(Scenario 1)- user::r--,user::ourfrd:r-- String(Scenario 2)- user::r-- File **** # file: /local/Desktop/myfile # owner: me # group:... (6 Replies)
Discussion started by: sarathy_a35
6 Replies

2. Shell Programming and Scripting

Change 10th column formatting.

Hi Experts, I created a powershell script to fetch user details from active directory and export it to a csv/excel. "abc","bcd","devloper;admin" "bcd","dca","tester;QA;admin" So here user abc is member of devloper and admin group and user bcd is a member of tester,QA and admin... (6 Replies)
Discussion started by: shekhar_4_u
6 Replies

3. Shell Programming and Scripting

How to search and replace string from nth column from a file?

I wanted to search for a string and replace it with other string from nth column of a file which is comma seperated which I am able to do with below # For Comma seperated file without quotes awk 'BEGIN{OFS=FS=","}$"'"$ColumnNo"'"=="'"$PPK"'"{$"'"$ColumnNo"'"="'"$NPK"'"}{print}' ${FileName} ... (5 Replies)
Discussion started by: Amit Joshi
5 Replies

4. Shell Programming and Scripting

How to replace the 10th column?

how to replace the 10th colum? Each line begins similarly, but they all ends variously. Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14,Col15,Col16,Col17 2015/03/14 15:00:04,2015/03/14 15:00:04,0,Server05,Omega-God,Beta_G,101011247,1,1,24,7,0,,339083645,1,1,... (9 Replies)
Discussion started by: ooilinlove
9 Replies

5. Shell Programming and Scripting

Replace empty string on particular column

Hi I would like to replace empty string with a particluar value, any suggessions with awk ? my input file is not delimited with any delimiters input 52001073M8000000004567777 5200107 000000004567778 5200107 000000004567779 52001073M8000000004567789 Expected output... (5 Replies)
Discussion started by: selvankj
5 Replies

6. UNIX for Dummies Questions & Answers

Search and replace string only in a particular column in a delimited file

I have file with multiple columns. Column values for a record may be same. Now i have to replace a column value(this can be same for the other columns) with new value. File.txt A,B,C,D,A,B,C,D,A,B,C,D A,B,C,D,A,B,C,D,A,B,C,D A,B,C,D,A,B,C,D,A,B,C,D A,B,C,D,A,B,C,D,A,B,C,D... (1 Reply)
Discussion started by: ksailesh
1 Replies

7. Shell Programming and Scripting

Print from second column onwards if $1<=40 using awk

I have a file like below 10 10 21 32 43 54 20 10 25 36 47 58 30 19 20 31 42 53 40 10 24 35 46 57 50 10 28 39 40 51 I need to check if $1 <= 40, then print from $2 onwards. If $1 > 40, the line is not printed. So I would have an output like this 10 21 32 43 54 10 25 36 47... (10 Replies)
Discussion started by: kristinu
10 Replies

8. UNIX for Advanced & Expert Users

Replace string in column

Hi, I want to replace string in column,Example i have file caleed a1.txt ,want to replace string "A12" with "A23" only in column2 ,not from file itself.Using sed command replace string in file itself. Thanks, Mohan (3 Replies)
Discussion started by: mohan705
3 Replies

9. Shell Programming and Scripting

Replace 10th Field by 2

Hello, I need some help ....i have a file with many number of fields i want to replace the 10th field of the file by number 2 .Also the delimeter of the file is | . Pls suggest and help.. Regards, (2 Replies)
Discussion started by: PradeepRed
2 Replies

10. Shell Programming and Scripting

Replace 10th column with a new column--- Terriblly hurry

Hi Can any one tell me how to replace the 10th column in a file(comma delimted) with a new file with a single column. Can any one Help me out of the please as soon as possible as i am in a terribley hurry!!!!!! Many THanks, (2 Replies)
Discussion started by: ahmedwaseem2000
2 Replies
Login or Register to Ask a Question