Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Search for a string and replace the searched string in the same position in samefile Post 302291261 by Whiteboard on Wednesday 25th of February 2009 05:57:43 AM
Old 02-25-2009
Code:
$ cat tab.txt
00000000 0 +00000000.00 2008/12/29 11:06:04 0108/12/29 10:05:37 00521363
 
$ awk '{sub(/^../,"20",$6); print}' OFS="\t" tab.txt
00000000        0       +00000000.00    2008/12/29      11:06:04        2008/12/29      10:05:37        00521363

$ cat samp.txt
00000000        0       +00000000.00    2008/12/29      11:06:04        0108/12/29

$ awk '{sub(/^../,"20",$6); print}' samp.txt
00000000 0 +00000000.00 2008/12/29 11:06:04 2008/12/29

$ awk '{sub(/^../,"20",$6); print}' OFS="\t" samp.txt
00000000        0       +00000000.00    2008/12/29      11:06:04        2008/12/29


Hope you can understand the above code with sample examples.....
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find the position of a string and replace with another string

Hi, I have a file named "Test_2008_01_21" The file contains a string "manual" that occurs many times in the file How can i find the positions of the string "manual" in the file Ex: if the string " manual " occurs three times in the file. i want to replace the second occurance of string... (6 Replies)
Discussion started by: bab123
6 Replies

2. Shell Programming and Scripting

Search for a string and replace the searched string in the same position

Hi All, My requisite is to search for the string "0108"(which is the year and has come in the wrong year format) in a particular column say 4th column in a tab delimited file and then replace it with 2008(the correct year format) in the same position where 0108 was found..The issue is the last... (15 Replies)
Discussion started by: ganesh_248
15 Replies

3. Shell Programming and Scripting

Search, replace string in file1 with string from (lookup table) file2?

Hello: I have another question. Please consider the following two sample, tab-delimited files: File_1: Abf1 YKL112w Abf1 YAL054c Abf1 YGL234w Ace2 YKL150w Ace2 YNL328c Cup9 YDR441c Cup9 YDR442w Cup9 YEL040w ... File 2: ... ABF1 YKL112W ACE2 YLR131C (9 Replies)
Discussion started by: gstuart
9 Replies

4. UNIX for Dummies Questions & Answers

Search a string in the file and then replace another string after that position

Hi I am looking for a particular string in a file.If the string exists, then I want to replace another string with some other text.Once replaced, search for the same text after that character position in the file. :wall: E.g: Actual File content: Hello Name: Nitin Raj Welcome to Unix... (4 Replies)
Discussion started by: dashing201
4 Replies

5. 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

6. Shell Programming and Scripting

Search a string in a text file and add another string at the particular position of a line

I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB and add/replace... (1 Reply)
Discussion started by: suryanarayana
1 Replies

7. Shell Programming and Scripting

Search String and extract few lines under the searched string

Need Assistance in shell programming... I have a huge file which has multiple stations and i wanted to search particular station and extract few lines from it and the rest is not needed Bold letters are the stations . The whole file has multiple stations . Below example i wanted to search... (4 Replies)
Discussion started by: ajayram_arya
4 Replies

8. Shell Programming and Scripting

Search for a string at a particular position and replace with blank based on position

Hi, I have a file with multiple lines(fixed width dat file). I want to search for '02' in the positions 45-46 and if available, in that lines, I need to replace value in position 359 with blank. As I am new to unix, I am not able to figure out how to do this. Can you please help me to achieve... (9 Replies)
Discussion started by: Pradhikshan
9 Replies

9. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies

10. 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
shblk(8)						      System Manager's Manual							  shblk(8)

NAME
shblk - Displays disk blocks, as unformatted hexadecimal numbers SYNOPSIS
/sbin/advfs/shblk [-sb start_block] [-bc block_count] special OPTIONS
Specifies the block on which to start. Specifies the number of blocks to display. OPERANDS
Specifies the device special file for the volume on which the block(s) are located. You can specify the volume by either its character or block device special file name. If you are executing the command from the mount point for the volume, you must specify the character device special file, as speci- fying the block device special file produces a device busy error. DESCRIPTION
The shblk command displays the selected blocks as hexadecimal numbers. The blocks are not formatted to any data or metadata representa- tion. You must be the root user to use this command. EXAMPLES
The following example shows a user whose current file system is mounted on /dev/disk/dsk3a attempting to display block 1 of the a partition on that device. Using the block device special file for the command does not work; using the character device special file does work. The display is truncated on the right due to page width limitations: # /sbin/advfs/shblk -sb 1 -bc 1 /dev/disk/dsk3a open: Device busy # /sbin/advfs/shblk -sb 1 -bc 1 /dev/rdisk/dsk3a 1: 47ff041f c0200002 20009800 00000000 a7a10000 d340000a 43c4153e 4... 1: b7fe0018 47ff0411 47ff0412 d34000e8 00000000 47ff041f 2ffe0000 4... 1: 243d0000 20218050 245d0000 204243e0 b7e10000 40211401 40410524 f... 1: 6bfa8001 47ff041f 2ffe0000 47ff041f 243dffff 23deffe0 20217f90 b... 1: a4410000 b53e0008 b55e0010 b57e0018 e440000b 47f00409 47e1040a 4... 1: a62a0000 47e90410 d34004ad e400000c a42a0008 214a0008 4160300b f... 1: 201fffff a75e0000 a53e0008 a55e0010 a57e0018 23de0020 6b9a8001 2... 1: 47eb0400 c3fffff7 47ff041f 47ff041f 23defff0 43f00011 b75e0000 4... 1: 47ff0412 47ff0413 47ff0414 47ff0415 d3400083 4807f680 a75e0000 4... 1: 40003520 23de0010 6b9a8001 47ff041f 23defff0 b75e0000 b53e0008 4... 1: d340049f 47e00412 47e21410 47e90411 47ff0413 47ff0414 47ff0415 d... 1: 4807d689 45207009 e5200002 201fffff c3e00001 43e00000 a75e0000 a... 1: 23de0010 6b9a8001 47ff041f 47ff041f 23deffe0 b75e0000 b53e0008 b... 1: 47f00409 d3400486 203f03ff 47e0040a 400107a2 4441048a e540000c 2... 1: 47e05410 47ff0411 47e90412 47e03413 47ff0414 47ff0415 d3400051 e... 1: 4140352a 21290001 f55ffff5 a75e0000 a53e0008 a55e0010 23de0020 6... # SEE ALSO
advfs(4), fs(4) shblk(8)
All times are GMT -4. The time now is 04:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy