01-29-2010
Sed - add text to start of line if 1st char anything but space
Problem: I have a lot of files, the files first line should always have 4 spaces before any text. Occasionally some of the files will miss the leading spaces and it's a problem. This is only in the first line.
So if there are 4 spaces then text, do nothing. If there are not 4 spaces, add 4 spaces, then put the text after the aforementioned 4 spaces.
I think I'm close, but I've spent a stupid amount of time googling with little luck.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I know that this my be really simple, but I'm having a hard time accomplishing it. I am trying to add a new line of text after finding a particular string of text in a file. Here's what I'm getting:
sed: command garbled: N/search_string/\\new_text/
I was using "N" to add a line after the... (3 Replies)
Discussion started by: douknownam
3 Replies
2. Shell Programming and Scripting
trying to remove the portion in red:
Data:
mds_ar/bin/uedw92wp.ksh: $AI_SQL/wkly.sql
mds_ar/bin/uedw92wp.ksh: $EDW_TMP/wkly.sql
output to be:
mds_ar/bin/uedw92wp.ksh: wkly.sql
mds_ar/bin/uedw92wp.ksh: wkly.sql
SED i'm trying to use:
sed 's/:+\//: /g' input_file.dat >... (11 Replies)
Discussion started by: danmauer
11 Replies
3. Shell Programming and Scripting
Im trying to add 5 blank spaces to the end of each line in a file in a sed script. I can figure out who o put the spaces pretty much anywhere else but at the end.
thanks
Karl (7 Replies)
Discussion started by: karlanderson
7 Replies
4. Shell Programming and Scripting
This is my first post, please be nice. I have tried to google and read different tutorials.
The task at hand is:
Input file input.txt (example)
abc123defhij-E-1234jslo
456ujs-W-abXjklp
From this file the task is to grep the -E- and -W- strings that are unique and write a new file... (5 Replies)
Discussion started by: TestTomas
5 Replies
5. Shell Programming and Scripting
what is the sed command to remove the first two characters of every line of a text file?
each line of the text file has the same amount of characters, and they are ALL NUMERIC. there are hundreds of lines though.
for example,
>cat file1.txt
10081551
10081599
10082234
10082259
20081134... (20 Replies)
Discussion started by: ajp7701
20 Replies
6. Shell Programming and Scripting
in vi editor I want to replace next line char by space
help me
eg:
input:
123
123
123
output:
123 123 123 (5 Replies)
Discussion started by: RahulJoshi
5 Replies
7. Shell Programming and Scripting
I've been playing with sed, trying to get it to insert the contents of somefile.txt after line 13 on anotherfile.txt. I tried searching for a line with regex and attempting to insert something on the next line with:
find ./anotherfile.txt -type f -exec sed -i -e '/^dog/cat/' {} \;
but it... (2 Replies)
Discussion started by: unclecameron
2 Replies
8. Shell Programming and Scripting
help
i need to add a "nfsd" in new line after cron
ex:
cron
rpcbind
output:
cron
nfsd
rpcbind
i use
sed -e "/cron/G; s/$/nfsd/" myfile
output:
cron
nfsd
rpcbindnfsd (5 Replies)
Discussion started by: jamilzain
5 Replies
9. Shell Programming and Scripting
hi guys,
im trying to add the following line in my xml file
<dbrollbacksegs <oa_var="s_db_rollback_segs">NOROLLBACK</dbrollbacksegs>
when ever i find the following line
<dbsharedpool oa_var="s_dbsharedpool_size">300000000</dbsharedpool>
I have succedded till adding a new line... (1 Reply)
Discussion started by: smarlaku
1 Replies
10. Shell Programming and Scripting
Hi all,
Is there other way to Add text at start and ending of every line?
here my script:
cat file.txt |awk '{print "<p align=\"justify\">"$0"</p>"}'
but the problem they put including white spaces, I only need those line have a sentence or text not an skip all have empty string or have... (7 Replies)
Discussion started by: lxdorney
7 Replies
DIFF3(1) GNU Tools DIFF3(1)
NAME
diff3 - find differences between three files
SYNOPSIS
diff3 [options] mine older yours
DESCRIPTION
The diff3 command compares three files and outputs descriptions of their differences.
The files to compare are mine, older, and yours. At most one of these three file names may be -, which tells diff3 to read the standard
input for that file.
Options
Below is a summary of all of the options that GNU diff3 accepts. Multiple single letter options (unless they take an argument) can be com-
bined into a single command line argument.
-a Treat all files as text and compare them line-by-line, even if they do not appear to be text.
-A Incorporate all changes from older to yours into mine, surrounding all conflicts with bracket lines.
-B Old behavior of -A. Shows non-conflicts.
-e Generate an ed script that incorporates all the changes from older to yours into mine.
-E Like -e, except bracket lines from overlapping changes' first and third files. With -e, an overlapping change looks like this:
<<<<<<< mine
lines from mine
=======
lines from yours
>>>>>>> yours
--ed Generate an ed script that incorporates all the changes from older to yours into mine.
--easy-only
Like -e, except output only the nonoverlapping changes.
-i Generate w and q commands at the end of the ed script for System V compatibility. This option must be combined with one of the
-AeExX3 options, and may not be combined with -m.
--initial-tab
Output a tab rather than two spaces before the text of a line in normal format. This causes the alignment of tabs in the line to
look normal.
-L label
--label=label
Use the label label for the brackets output by the -A, -E and -X options. This option may be given up to three times, one for each
input file. The default labels are the names of the input files. Thus diff3 -L X -L Y -L Z -m A B C acts like diff3 -m A B C ,
except that the output looks like it came from files named X, Y and Z rather than from files named A, B and C.
-m
--merge
Apply the edit script to the first file and send the result to standard output. Unlike piping the output from diff3 to ed, this
works even for binary files and incomplete lines. -A is assumed if no edit script option is specified.
--overlap-only
Like -e, except output only the overlapping changes.
--show-all
Incorporate all unmerged changes from older to yours into mine, surrounding all overlapping changes with bracket lines.
--show-overlap
Like -e, except bracket lines from overlapping changes' first and third files.
-T Output a tab rather than two spaces before the text of a line in normal format. This causes the alignment of tabs in the line to
look normal.
--text Treat all files as text and compare them line-by-line, even if they do not appear to be text.
-v
--version
Output the version number of diff3.
-x Like -e, except output only the overlapping changes.
-X Like -E, except output only the overlapping changes. In other words, like -x, except bracket changes as in -E.
-3 Like -e, except output only the nonoverlapping changes.
SEE ALSO
cmp(1), comm(1), diff(1), ed(1), patch(1), sdiff(1).
DIAGNOSTICS
An exit status of 0 means diff3 was successful, 1 means some conflicts were found, and 2 means trouble.
GNU Tools 22sep1993 DIFF3(1)