Sponsored Content
Top Forums Shell Programming and Scripting Edit lines in file preserving part of it Post 303041379 by Scrutinizer on Friday 22nd of November 2019 02:48:55 AM
Old 11-22-2019
You are welcome Cacializ. GNU sed -i has a backup option:
Code:
-i[SUFFIX], --in-place[=SUFFIX]

The BSD sed man page says you should always use it. Anyway in general it is always a good idea to have backups and stuff like this would be best to put in a git repository and then you can just checkout the original files if something goes wrong..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Edit number of lines in a file to single line

Greetings, I have a file: hostnames.txt which has - # cat hostnames.txt machine1 machine2 I need the output to be saved to a variable as: HOSTNAMELIST=machine1,machine2 Please advise. Thanks, Chiru (3 Replies)
Discussion started by: chiru_h
3 Replies

2. Shell Programming and Scripting

Using cp: preserving file/folder attributes and auto creating folders

Hi, Is there a way to use cp in such a way that when a file is copied to a destination, the required destination folders are automatically created with the proper permissions, and the resulting copied file has the same attributes as the original. For example if I copied... (1 Reply)
Discussion started by: pcwiz
1 Replies

3. Shell Programming and Scripting

To Read a File and Insert a part of the lines into the database

Hi Guys I need to have a shell script which reads a log file and insert a part of each line into the database. Some sample lines in the file are as below. 20091112091359 MED_RQACK : user_data=60173054304,100232120,20091112091359,;ask_status=0;ask_reason=OK;msg_id=20091112091319... (5 Replies)
Discussion started by: Somanadh
5 Replies

4. Shell Programming and Scripting

How to edit file sections that cross multiple lines?

Hello, I'm wondering where I could go to learn how to edit file sections that cross multiple lines. I'm wanting to write scripts that will add Gnome menu entries for all users on a system for scripts I write, etc. I can search an replace simple examples with sed, but this seems more complex. ... (8 Replies)
Discussion started by: Narnie
8 Replies

5. Shell Programming and Scripting

Help in preserving special characters from input file

Hi Forum. I've tried to search online for a solution but I cannot seem to find one. Hopefully, someone here can help me out. I would appreciate it. Input file abc.txt: $InputFile_Borrower=CMTSLST\EDW_COMMERCIAL_MTGE_BORROWER_dat.lst... (14 Replies)
Discussion started by: pchang
14 Replies

6. Shell Programming and Scripting

Preserving Empty Lines while Replacing Numbers

Greetings, I am using tcsh to write a script that will replace the numbers in a file with a single number, the caveat is that this file has blank lines which are necessary for another step down the line so I need to preserve the blank lines. I have tried sed and awk but both will collapse the... (1 Reply)
Discussion started by: bonesy
1 Replies

7. Shell Programming and Scripting

Script to Check & Edit Content of a file (Addition of comma in each lines of code)

Hi all, I need to write an automated bash shell script which performs such operations: 1. Grep the header of everyline with the initial of "T" in "FILE_A" 2. Perform a for loop, Count the numbers of comma in the line of code, if (no. of comma < 17) ADD the comma until 17; ... (2 Replies)
Discussion started by: big_nutz
2 Replies

8. Shell Programming and Scripting

How to get awk to edit in place and join all lines in text file

Hi, I lack the utter fundamentals on how to craft an awk script. I have hundreds of text files that were mangled by .doc format so all the lines are broken up so I need to join all of the lines of text into a single line. Normally I use vim command "ggVGJ" to join all lines but with so many... (3 Replies)
Discussion started by: n00ti
3 Replies

9. Shell Programming and Scripting

Preserving file format and spacing in output file

Hi I have a file with the following structure "VATTENFALL GLOBAL" "Vattenfall Tray" "BARCLAYS BANK LONDON" "Capula" "P1 AGEAS GLOBAL COMPANY" "AAC - Optiver" The requirement is like this 1) Take 2 input... (16 Replies)
Discussion started by: sudeep.id
16 Replies

10. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies
RREP(1) 						      General Commands Manual							   RREP(1)

NAME
rrep - replace patterns in files. SYNOPSIS
rrep [OPTIONS] PATTERN REPLACEMENT [FILE...] DESCRIPTION
The rrep utility searches input FILEs for matches to a given PATTERN and replaces those matches by a given REPLACEMENT. The pattern is, by default, a basic regular expression. The replacement string may contain special characters to refer to portions of the matched pattern. Binary files are, by default, ignored. A file is regarded as binary if it contains the null character. OPTIONS
-E, --extended-regexp PATTERN is interpreted as an extended regular expression (ERE). -F, --fixed-strings PATTERN and REPLACEMENT are interpreted as fixed strings, not as regular expressions or escape sequences. -R, -r, --recursive Each directory that is given on the command line is processed recursively. Files and sub-directories starting with the . character are, by default, ignored. --include=FILE_PATTERN Only files are processed that match the pattern FILE_PATTERN, except for files that are specifically given on the command line. *, ?, and [...] can be used as wildcards in FILE_PATTERN. Wildcards and backslash characters can be quoted with . --exclude=FILE_PATTERN Files that match the pattern FILE_PATTERN will be skipped, except for files that are specifically given on the command line (using wildcard matching as described under --include). --exclude-dir=PATTERN Directories that match PATTERN will be skipped, except for files that are specifically given on the command line (using wildcard matching as described under --include). -V, --version Print the version number of rrep. -S SUFFIX, --suffix=SUFFIX Override default backup suffix. This option implicitly activates backups. -a, --all Files and sub-directories starting with the . character in recursively processed directories (see --recursive) are processed as well. -b Backup before overwriting files. The backup files are written into the directory of the original file. Equivalent to using --backup=existing. --backup[=CONTROL] Like -b but accepts a version control argument. The file name of the backup file is appended by a ~ character. The backup suffix is ~, unless set with --suffix or SIMPLE_BACKUP_SUFFIX. The version control method may be selected via the --backup option or through the VERSION_CONTROL environment variable. Here are the values: none, off never make backups (even if --backup is given) numbered, t make numbered backups existing, nil numbered if numbered backups exist, simple otherwise simple, never always make simple backups --binary Do not ignore binary files. A file is regarded as binary if it contains the null character . --dry-run The replacement is just simulated. No file is actually modified. -e PATTERN, --regexp=PATTERN Use PATTERN for matching. This option can be used to specify a pattern beginning with -. -h, --help Display a help message that descibes the command line options and exit afterwards. -i, --ignore-case Case distinctions in PATTERN are ignored. --keep-times The original access and modification times of files and directories are restored after processing. -p REPLACEMENT, --replace-with=REPLACEMENT Use REPLACEMENT for substitution. --interactive Each time before a file is modified the user is prompted and can cancel the modification. -q, --quiet, --silent All normal output messages are suppressed. -s, --no-messages All error messages are suppressed. -w, --word-regexp Only those matches of PATTERN are replaced that match whole words. -x, --line-regexp Only those matches of PATTERN are replaced that match whole lines. EXIT STATUS
Exit status is 1 if any error occurs, 0 otherwise. AUTHOR
Written by Arno Onken. REPORTING BUGS
If you find a bug in rrep, please send electronic mail to <asnelt@asnelt.org>. Include the version number, which you can find by running rrep --version. Also include in your message the output that the program produced and the output you expected. If you have other questions, comments or suggestions about rrep, contact the author via electronic mail to <asnelt@asnelt.org>. The author will try to help you out, although he may not have time to fix your problems. COPYRIGHT
Copyright 2011 Arno Onken This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. SEE ALSO
Regular Manual Pages find(1), grep(1), sed(1), xargs(1), regex(7). TeXinfo Documentation The full documentation for rrep is maintained as a TeXinfo manual. If the info and rrep programs are properly installed at your site, the command info rrep should give you access to the complete manual. User Commands rrep 1.3.3 RREP(1)
All times are GMT -4. The time now is 11:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy