Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Search a string in the file and then replace another string after that position Post 302529693 by yazu on Friday 10th of June 2011 04:40:38 AM
Old 06-10-2011
Code:
% cat testfile
Hello
Name: Nitin Raj
Welcome to Unix World.
This is very helpful
.
.
.
Hello
Name: ?ashing
This is nice forum.

% cat testfile | sed '/Hello/ n; s/Name/IDENTITY/'
Hello
IDENTITY: Nitin Raj
Welcome to Unix World.
This is very helpful
.
.
.
Hello
IDENTITY: ?ashing
This is nice forum.

 

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. UNIX for Dummies Questions & Answers

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

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 in the same file..The... (27 Replies)
Discussion started by: ganesh_248
27 Replies

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

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

6. Shell Programming and Scripting

Search string at a particular position in a file

Hi, i have a text file as : abc 0 1 Pass hjk 1 1 Pass bhk 0 0 Fail jjh 8 2 Pass nkji 0 1 Pass Now I want to check that if 1st column is jjh , then , store the value of 3rd string of that line in a variable. Hence, 2... (8 Replies)
Discussion started by: Anamika08
8 Replies

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

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

9. UNIX for Dummies Questions & Answers

How do I replace a string in file that is in a certain position with spaces?

I am trying to replace the string in position 26 through 35 of the data file with 10 spaces and I want the remaining file to stay as is, the record length is over 900 characters? I am trying to use the AWK and substr but I am not getting it formatted correctly. Before... (6 Replies)
Discussion started by: fnwine1500
6 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
TRUNCATE(7)							   SQL Commands 						       TRUNCATE(7)

NAME
TRUNCATE - empty a table or set of tables SYNOPSIS
TRUNCATE [ TABLE ] [ ONLY ] name [, ... ] [ RESTART IDENTITY | CONTINUE IDENTITY ] [ CASCADE | RESTRICT ] DESCRIPTION
TRUNCATE quickly removes all rows from a set of tables. It has the same effect as an unqualified DELETE on each table, but since it does not actually scan the tables it is faster. Furthermore, it reclaims disk space immediately, rather than requiring a subsequent VACUUM oper- ation. This is most useful on large tables. PARAMETERS
name The name (optionally schema-qualified) of a table to be truncated. If ONLY is specified, only that table is truncated. If ONLY is not specified, the table and all its descendant tables (if any) are truncated. RESTART IDENTITY Automatically restart sequences owned by columns of the truncated table(s). CONTINUE IDENTITY Do not change the values of sequences. This is the default. CASCADE Automatically truncate all tables that have foreign-key references to any of the named tables, or to any tables added to the group due to CASCADE. RESTRICT Refuse to truncate if any of the tables have foreign-key references from tables that are not listed in the command. This is the default. NOTES
You must have the TRUNCATE privilege on a table to truncate it. TRUNCATE acquires an ACCESS EXCLUSIVE lock on each table it operates on, which blocks all other concurrent operations on the table. If con- current access to a table is required, then the DELETE command should be used instead. TRUNCATE cannot be used on a table that has foreign-key references from other tables, unless all such tables are also truncated in the same command. Checking validity in such cases would require table scans, and the whole point is not to do one. The CASCADE option can be used to automatically include all dependent tables -- but be very careful when using this option, or else you might lose data you did not intend to! TRUNCATE will not fire any ON DELETE triggers that might exist for the tables. But it will fire ON TRUNCATE triggers. If ON TRUNCATE trig- gers are defined for any of the tables, then all BEFORE TRUNCATE triggers are fired before any truncation happens, and all AFTER TRUNCATE triggers are fired after the last truncation is performed. The triggers will fire in the order that the tables are to be processed (first those listed in the command, and then any that were added due to cascading). Warning: TRUNCATE is not MVCC-safe (see in the documentation for general information about MVCC). After truncation, the table will appear empty to all concurrent transactions, even if they are using a snapshot taken before the truncation occurred. This will only be an issue for a transaction that did not access the truncated table before the truncation happened -- any transaction that has done so would hold at least an ACCESS SHARE lock, which would block TRUNCATE until that transaction completes. So truncation will not cause any apparent inconsistency in the table contents for successive queries on the same table, but it could cause visible inconsistency between the contents of the truncated table and other tables in the database. TRUNCATE is transaction-safe with respect to the data in the tables: the truncation will be safely rolled back if the surrounding transac- tion does not commit. Warning: Any ALTER SEQUENCE RESTART operations performed as a consequence of using the RESTART IDENTITY option are nontransactional and will not be rolled back on failure. To minimize the risk, these operations are performed only after all the rest of TRUNCATE's work is done. However, there is still a risk if TRUNCATE is performed inside a transaction block that is aborted afterwards. For example, consider BEGIN; TRUNCATE TABLE foo RESTART IDENTITY; COPY foo FROM ...; COMMIT; If the COPY fails partway through, the table data rolls back correctly, but the sequences will be left with values that are probably smaller than they had before, possibly leading to duplicate-key failures or other problems in later transactions. If this is likely to be a problem, it's best to avoid using RESTART IDENTITY, and accept that the new contents of the table will have higher serial numbers than the old. EXAMPLES
Truncate the tables bigtable and fattable: TRUNCATE bigtable, fattable; The same, and also reset any associated sequence generators: TRUNCATE bigtable, fattable RESTART IDENTITY; Truncate the table othertable, and cascade to any tables that reference othertable via foreign-key constraints: TRUNCATE othertable CASCADE; COMPATIBILITY
The SQL:2008 standard includes a TRUNCATE command with the syntax TRUNCATE TABLE tablename. The clauses CONTINUE IDENTITY/RESTART IDENTITY also appear in that standard but have slightly different but related meanings. Some of the concurrency behavior of this command is left implementation-defined by the standard, so the above notes should be considered and compared with other implementations if necessary. SQL - Language Statements 2010-05-14 TRUNCATE(7)
All times are GMT -4. The time now is 01:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy