General :: Insert Tab At Beginning Of Each Line In File?

Aug 5, 2010

I am trying to create a shell script where a user can specify a file with a list of logins and the script will create a batch file with specific information in specific columns.

Example:

loginfile.txt has

User1
User2
User3

I need the output to be as below:

1 User1 Date 12/31/9999
2 User2 Date 12/31/9999
3 User3 Date 12/31/9999

Where the columns are separated as below.

1[tab][tab]User1[tab]date +%D[tab]12/31/9999
2[tab][tab]User2[tab]date +%D[tab]12/31/9999
3[tab][tab]User3[tab]date +%D[tab]12/31/9999

I can use the nl utility to get the numbers easily enough, but I need two tab separations between the number and the user list. Is there a sed command that will insert at the beginning of each line? If so I can just run nl after I get some tabs up in the front.

View 2 Replies


ADVERTISEMENT

Programming :: Perl - Delete Line From Text File With Duplicate Match At Beginning Of Line

Apr 1, 2009

Was wondering if any perl guru's could help me with a quick log file adjustment. I have a text file that looks like so (tabs and newlines are revealed so you can see what separates the data):

There are maybe 100 lines of text in this file at any given time. I need to delete all duplicate lines only looking at the first bit of text prior to the first tab. It doesn't matter which one gets deleted as long as there are no two lines that begin with that same text at the beginning before the first tab. So in this example, either the fist line "1234" or the last line "1234" would need to be deleted. I already have code in my script that opens the files - I just need the code to read the text into an array and the part that would find matches based on the above criteria, and make the deletions.

If it would be easier, I can even do a system call and use SED (v4.1.5) and/or AWK (3.1.5) instead.

View 7 Replies View Related

General :: Insert Line Into A File With A Command?

Jan 4, 2010

I would like to insert a line into the /etc/sysconfig/iptables with a command like sed or with any script. How can I insert this line:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

but under the line "-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT"

View 2 Replies View Related

General :: Insert Text In The Last Line Of A File With Sed Command?

Oct 4, 2010

I want to insert the text "DB dept" in the last line of passwd file which looks like this right now

Quote:

newuser:x:717:717::/home/sacharje:/bin/bash

And I want it to be like this:

Quote:

newuser:x:717:717: DB dept:/home/sacharje:/bin/bash

I tried to do that with sed but failed, I'd like to know the proper syntex with sed to achieve this.

View 7 Replies View Related

General :: Insert Text To A File Using Command Line?

Jan 28, 2010

I need to be able to edit a file from the commend line as I intend to script this operation, the file is called menu.lst The original is as below

Code:

titleUbuntu 8.04.3 LTS, kernel 2.6.24-24-generic
root(hd0,0)
kernel/boot/vmlinuz-2.6.24-24-generic root=UUID=b09feb23-5524-4ec4-862f-94700b968f64 ro quiet splash

[code]....

View 4 Replies View Related

General :: Recognized Pragma - Insert At The Beginning Of A Text Document To Designate It To Be UTF-8 Encoded

Jun 4, 2011

Is there some kind of universally recognized pragma that one can insert at the beginning of a text document to designate it to be UTF-8 encoded (or any other encoding)? I've seen certain editors insert encoding comments, and one or two compilers that have an encoding pragma. But I was wondering if anyone has tried to establish some kind of universal tag format for text documents.

View 1 Replies View Related

Programming :: Insert A Line/value After A Particular Line In File With Sed?

Jan 13, 2010

I need to run a command in a shell script to insert a line in a file, after it finds certain line. To add the line 'user = mysql' after the line [mysqld] in file /etc/my.cnf

View 3 Replies View Related

Programming :: Insert Each Line Of One File To The Another File After Certain Lines?

Jul 2, 2010

i have two files with thousands of line, I am trying to combine these two files but i want to insert each line of one file to the another file after certain lines. I am using awk with the following command but it does not work.cat file1 | awk ' { print $0; if (NR%3004==0) {print "file2"}}' > outputfile

View 14 Replies View Related

General :: Insert A Line Into A Text File Using "sed" Command?

Sep 18, 2010

I've been reading tutorials of Linux sed command, but haven't got anything yet. the problem is : I want to insert a line into my DNS database file which has a pattern like below:

<Domain name> 3tabs here <IN> <A> <ip address>

the question is : how to add a line into a file like this using linux sed command? I have problem inserting tabs and the spaces!

View 7 Replies View Related

Programming :: Insert A Line In The Test File With Sed?

Jul 15, 2010

I have following file workers file: There are 800 entries like this.

# consensus/uat
worker.consensus-uat1.host=lonlx10409
worker.consensus-uat1.port=13702
worker.consensus-uat1.type=ajp13

[code]....

I want to insert one line just below the line starting with "woker.list". I think sed can do it but I am not aware.

View 14 Replies View Related

General :: Bash - Add Text At The Beginning Of A Line

Feb 28, 2011

I have a lot a folders, each named by a number, and in each of these folders I have a specific file (stddev.dat) containing a single line (of numbers) I need to have a single file with each line being one of the stddev.dat (no matter if it is sorted or not), and also I need to add at the begining of each line the number of the folder it comes from.

I 'm no bash expert, and the "add at the begining of the line" is a bit of problem to me". Here is what I've come up with so far, just to put everything in one file, (and also if you know a better/more elegant way to do the same thing I've done, I'm listening)

[Code]...

View 6 Replies View Related

General :: Sed Command - Find Line Not Beginning With Double Quote

Mar 15, 2011

I need to find each line in a file which does NOT begin with a double quote (") and append that line to the previous line. I have been successful doing this using the following command:
cat filname.csv | sed -e :a -e '$!Ns/
[^"]//;ta -e 'P;D' > newfilename.csv

My issue is the substitution. As you would expect after the line is appended to the previous line the first character is removed. I need it to not be removed. I tried:
cat filname.csv | sed -e :a -e '$!Ns/
[^"]/&/;ta -e 'P;D' > newfilename.csv
but it just hangs.

Goal:
Input:
"line 1"
line 2
Output with existing sed command is:
line 1ine2
I need it to be line1line2.

View 9 Replies View Related

Programming :: Insert Line Using Sed Or Awk At Line Using Line Number As Variable

Jul 25, 2011

I want to insert a line at a particular line number using sed or awk. where line number is not fixed and is in form of variable.

I want to use variable in sed or awk command.I tried something like below, but no luck.

View 7 Replies View Related

General :: Insert Text To A Specified Line?

Aug 23, 2009

Code:

sed -n '123p' file

that will print line 123 but how might I insert text to a specified line?

View 3 Replies View Related

General :: Deleting A File Beginning With '?'

Jan 26, 2010

I have found a file beginning with a question mark in my home dir, not sure how the hell it got there. It's from a downloaded rar i think.

Does anyone know how to do this?

View 14 Replies View Related

Debian :: Add Tabs At The Beginning Of Each Line?

Dec 6, 2010

I want to add something at the end of each line, from line 4 to line 8, in vim? How can i do that? I know adding at the beginning is like: 4,8: normal: i# What i want to add contains special characters ( here it is: <br/> ) , in case that matters.

I want to add tabs at the beginning of each line, from line 6 to line 12. How?

View 1 Replies View Related

Programming :: Add String On The Beginning And End Of The Line ?

Aug 3, 2010

I need to output of a script to a file with tags.

I'm trying sed and was able to put a tag on the end of the line

Code:

Output is

Quote:

What I need to have is

Quote:

I'm thinking of I redirect my first sed command to a file and then use sed again to put <group> at the beginning of the line. My problem is how to put <group> to all beginning of the string.

View 2 Replies View Related

Programming :: Function Which Removes '#' From Beginning Of Line?

Apr 16, 2010

I try to do a function which removes '#' from beginning of line. But if there is not '#' then add it on beginning of line. I try something like this, can you correct me?

Code:
awk '
!/^#/{ sub(/^[^#]*/,"#$0","'$line'")
}
/^#/{ sub(/#/,"","'$line'")
}'

View 14 Replies View Related

Programming :: Expect: Reacting On A $ At The Beginning Of A Line?

Oct 17, 2010

I am having some difficulties with an expect script. What I want is that as soon as expect sees a newline followed by a dollarsign ($), that interact is done. So I would expect something like this to work:

Code:
"
$" { interact }
However it doesn't.
This is debugging output:
Code:
expect: continuing expect
expect: does " " (spawn_id exp6) match glob pattern "#"? no

[Code]...

View 3 Replies View Related

General :: Filename Beginning With Left Bracket: File Cannot Be Erased

Nov 28, 2010

Kernel 2.6.21.5, Slackware 12.0

I saved a page from Linuxquestions. It was saved under a filename beginning with '[' (left square bracket). And I now can't delete the file. Unfortunately I cannot send you a screenshot because opening a terminal in the GUI makes ls behave differently. I shall try to describe, assuming the file is in dir '.'. Also let '[SOLVED]foo.html' be the file in question:

Code:
$ ls
<the file is listed>
$ ls [*
/bin/ls: cannot access [*: No such file or directory
$

If I want the hdd to get rid of this file, what should I do? Any hint will be welcome.

View 2 Replies View Related

Programming :: Sed - Replace All Spaces At Beginning Of Line With The Number 1?

Jun 21, 2010

Does any one know what syntax i could use to allow me to replace all instances at the beginning of a line with ones.

Before :

Code:
----------------------------------------------------------------------
Logical device information
----------------------------------------------------------------------
Logical device number 0
Logical device name : RAID1Mirror
RAID level : 1
Status of logical device : Optimal

After

Code:
----------------------------------------------------------------------
Logical device information
----------------------------------------------------------------------
Logical device number 0
111Logical device name : RAID1Mirror
1111RAID level : 1
11111Status of logical device : Optimal

View 12 Replies View Related

General :: Script To Insert Number Of Lines In A File To The Start Of The File?

Sep 17, 2009

I'm looking for a way to insert the number of lines in a file to the start of the aformentioned file. This should be simple but as I am not used to scripts in Linux, I am finding it tough going. I can find the number of lines in a file easily enough via

filesize=$(awk 'END {print NR}' $1)

but as for inserting this into the first line, i'm failing to do so. I've tried some of the other approaches on these forums but none so far have been able to do so.

I've tried:

sed '1i$filesize' $1

but sed i requires a string, not a variable so no go I've also tried:

mv "$1" "${1}.bak" 2>/dev/null || touch "${1}.bak"
cat $filesize "${1}.bak" >"$1"

but again with no luck as cat seems to need an input stream Just to recap, i want to insert a line at the start of a given file that holds the number of lines the original file has.

ie the file:

a
b
c
d
e

should become:

5
a
b
c

[code].....

View 3 Replies View Related

General :: Insert A Folder Into A ZIP File?

Aug 11, 2011

I'm a newbie on Linux and had to do something like this with the zip command:

My folder structure inside a zip file abc.zip is code...

It would move into abc.zip as folder3/textfile.txt (the hierarchy preserved)
Also used a -j switch (help said it junked the path info and it did but) - it would move only into abc.zip and sit at the same level as folder1 and folder2 instead of replacing the textfile.txt within abc.zip/folder1

My question is - I want to replace the abc.zip/folder1/textfile.txt with the one inside seconddir/folder3/textfile.txt.

How do I achieve this via the command line interface?

View 3 Replies View Related

General :: Insert Texts In A File By Using Shell?

Jan 26, 2011

I'm using fedora 14...i would like to insert few texts to a file in shell prompt(may be useful in scripting for in the future)...for eg,

[root@ruby ~]# cat > hello
1
2
2

[code]....

so in the above file i need to add the line "new line added" near the number 4 in the above file ....how can be this done ...?

View 8 Replies View Related

Programming :: Insert A Character In Line Using Sed/awk?

Jul 25, 2011

I have a string as below

LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined

Want the above string to be modified as

LogFormat "%h %l %u %D %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined

inserting %D after %u in the string

View 3 Replies View Related

Programming :: Insert Paragraph At Particular Line?

Jul 26, 2011

I want to copy below content to a file after line 200.

Alias /A/ "/A/B/C/D/"
<Directory "/E/F/G/H/">
Options Indexes MultiViews
AllowOverride None

[Code]....

Or is it possible if I can copy this content in some other file and insert to the main file.

View 4 Replies View Related

Programming :: Sed Insert Line With Leading Spaces?

Mar 3, 2011

I'm trying to insert a line using sed that has leading spaces before the text. Sed seems to be just dropping the spaces and only inserting the text. Any ideas what I'm missing?

Code:

NAM=rb134
sed -i.bak -e "$i
host ${NAM} {" /etc/crap

Instead of inserting a line with 8 leading spaces inserts it with "host" at the beginning of the line. I tried

Code:

NAM=rb134
sed -i.bak -e "$i
^ host ${NAM} {" /etc/crap

but it put the "^" at the begging of the line.

View 6 Replies View Related

Programming :: Insert Line Of Text Prior To Pattern Only Once?

Jun 29, 2010

I have a file like so:

Code:

one
two
three
four

I would like to insert prior to the word "three" all items from this second file with the following contents:

Code:

four
three
two
one

Now my issue is, and I have been using both sed and awk currently, that after the second line of the new file is read there will of course now be 2 copies of the word "three" but I would like to only insert the final 2 words, ie "two" and "one" prior to only the first occurrence of the word "three" so final file will look like:

Code:

one
two
four

[code]....

So here there is now only one of each word from the second file joined to make the new file. For simple code I have tried something like the following:

Code:

while read line
do
awk -v n=$line '!f && /three/{print n;f++}1' file1 > tmp_file
mv tmp_file file1
done < file2

Now this works but seems very clumsy to me. There is obviously a better sed and / or awk out there.

View 5 Replies View Related

General :: Scripting - Feed An Input File Into An If Statement Line-by-line

Dec 23, 2009

I am trying to write a script that takes an input file ($FileName) and an intermediate file ($FileName.info) and removes lines from $FileName if the value in $2 of $FileName.info is <75.

I can't figure out how to feed only one line of the .info file to the if statement at a time so that it will perceive it as an integer instead of a list.

The error I am getting now is ./script.sh: line 6: [: : integer expression expected

Sample input $FileName

Code:

Code:

Code:

Script so far:

Code:

View 10 Replies View Related

General :: Parse A File And Print Each Line That Ends With Matching Pattern (if The Next Line Is Blank)

Aug 2, 2010

I've written a script to parse a file and print each line that ends with matching pattern, if the next line is blank. The pattern lines are the result of md5sum $i|sed 's/path///g' so that only md5 and filename appear. Here's what I'm using.

Quote:
for fline in `sed -n '/.*.ext$/p' file1`
do
if [ "`sed -n -e '/'"$fline"'/ {n; p;}' file1`" == "" ]
then
echo ""$fline" has no info" >>file2
fi
done
[Code]....

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved