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


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 :: Echo Text With New Line In Bash?

Jun 21, 2010

I would like to append text to a file. so i wrote in bashecho text >> file.confHowever it doesnt leave a new line. So i can only do this once. How do i add a new line?

View 2 Replies View Related

General :: Adding Text To End Of Particular Line In Bash

Nov 30, 2010

I am looking at how to add particular text to a file in bash.Here is what I am trying to do:In the /etc/grub.conf file, I am trying to add "audit=1" (without the quotes) to the end of the kernel line...such as:kernel /vmlinuz-2.6.18-194.el5 ro root=LABEL=/1 rhgb quiet audit=1

As there are a few different lines in this file, I am only looking to add the "audit=1" to the above line via a bash script.

View 7 Replies View Related

Programming :: BASH: Each Line Of Multiple Text Files Gets Added To One Line?

Sep 12, 2010

I currently have 3 files with floating point data that I wish to have in a single file with the format:

Code:

F1 F1 F3 Output
a1 b1 c1 a1 b1 c1
a2 b2 c2 a2 b2 c2
a3 b3 c3 a3 b3 c3
a4 b4 c4 a4 b4 c4

View 3 Replies View Related

Programming :: Bash: Read A Text File Line By Line?

Jul 7, 2011

bash 3.1.17(2) I'm trying do write a shell script which must operate on each line of an ASCII text file. So, all the code must be inside a loop, and inside the loop, the first thing should be to read the next line from the file. I have the bash read command. But it reads from stdin. Any way to make read from a file?

View 6 Replies View Related

Software :: Use Sed To Include A Text File In The Beginning Of Other Text Files Inside A Folder And Its Subfolders?

Jun 1, 2010

Can I use sed to include a text file in the beginning of other text files inside a folder and its subfolders? So it should be recursive.

View 4 Replies View Related

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 View Related

Programming :: Adding Lines Of Text To Beginning Of Text File

Jan 19, 2009

I need to insert 3-4 lines of text to the beginning of a text file. The file is a largish MYSQL dump, the result of a backup shell script. This shell script should insert the required text.I've wrestled with sed, but lost.

View 2 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

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 :: Write An If Statement For The First Line Of A Text File Bash?

Feb 15, 2011

At the moment I got my md5sum checking working which I write to a text file and see below.

If the md5sum works it will write the output to check2.md5 test.txt: OK

If the md5sum fails it will write test.txt: FAILED

How do I write if statement to check the output whether or not the md5sum failed or not ?

check1="/home/ops/Desktop/test1/check1.md5"
check2="/home/ops/Desktop/test1/check2.md5"
cd /home/ops/Desktop/test1
md5sum test.txt > $check1

[Code]....

View 2 Replies View Related

General :: Match And Combine 2 Text Files Line By Line

Mar 21, 2011

This solution works but is slow with large files. I am looking for a faster solution.

The 2 files contain filenames, one of them has associated data I want to append to the other file's matching filenames

file1:

file2:

I append file2 by matching the unique_filenames and appending them with the tag data and some formatting

appended file2:


Here is the SLOW code

while read inputline.

View 9 Replies View Related

Programming :: Append Text To The Beginning Of A File?

Jan 14, 2010

I am trying to append text to the beginning of a file. This is what I have so far.

Code:
date_default_timezone_set('America/Chicago');
$date=date("m-d-Y g:i:s a");

[code]....

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

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

Programming :: Bash Text To Variable Accessing Individual Text Lines?

May 2, 2010

i am on processing text tasks And i found that if you assign a text to a variable is chomp'ed automatically the newline

Code:

variable=$(cat file.txt)

The problem is i can only access the items/lines using:

Code:

for line in $variable
do
echo $line
# Other commands
done

how do i convert this to an indexed array. More importantly, how do i get access to individual $line[0], ..., $line[n] Another thing, if the file.txt, has lines with spaces it is a mess using the for...in..., but echoing prints line by line...o_0

View 11 Replies View Related

General :: Getting Numbers From A Line Of Text?

May 10, 2010

I'm working with a rather large file of data taking from a tracking program on my phone, and trying to pull only the longitude and latitude from it. Any given line in the data looks more or less like this:

{"lon":-122.3083848,"time":1.273515839496E9,"source":"skyhook","nap":28,"altitude":0,"name":"location","hpe" :29,"bearing":0,"ncell":0,"lat":47.6544453}

I've run it through this command:

grep skyhook log-2010-05-10_18-17-28.json | cut -d"," -f1,10

to get this:

{"lon":-122.30872015,"lat":47.65812201}
{"lon":-122.3076686,"lat":47.6569975}
{"lon":-122.3079161,"lat":47.656395}
{"lon":-122.3096168,"lat":47.656218}
{"lon":-122.3096285,"lat":47.656206}

Which is a lot nicer, but I would prefer not to have to hand remove the non-number characters by hand since there are thousands of data points. what I could do to get it to just be longitude and latitude in 'number number' format?

View 8 Replies View Related

General :: Remove Specified Line From Text?

Feb 12, 2011

I wish to move a specified line from a text file:

Quote:

ltoremove=5 #remove 5th line
i=1
while read line ; do

[Code]....

how should this actually be done? is there a shorter faster way to do this?

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

Programming :: Delete Line Of Text From Text File Via Shell?

Jan 13, 2010

I have to delete a certain line of text from the a textfile via ubuntu's shell scripting.I have done research, and it seems that most people advocate the usage of sed /d option. sed makes does not edit the text file. Hence, most options I discovered involved the use of a temporary variable/textfile and then overwriting the old file with the temporary new file. Is there anyway whereby I can bypass the use of temporary storage containers? I hope there is any magical combination of commands to edit the file directly.

View 3 Replies View Related

General :: Bash - Search For A Text Pattern?

Nov 28, 2010

I need to search for a string "teststring" in all *.java files coming under /home/user1/ (including subfolders). How can I do it in linux via shell command.

View 5 Replies View Related

Software :: Grep Query To List 1 Line (which Is Fixed) And The Next Line After It (variable Text)

Jan 20, 2011

How can I list the following with grep. I want to extract 2 lines fron a text file The fixed known part if it exists will static text and the text line after it will change.

A sample file
.
.
textline1

[code]....

If the fixed part does Not exist how can I return error code 1

View 3 Replies View Related

Programming :: Add Text Before Line Number In Text File?

May 3, 2010

a sed command to add a text before line number in text file? I have text file with 500 lines, and i want to add 3 more lines with text after line 300, OR before line 302, isn't no problem.

View 16 Replies View Related

Programming :: Open Two Text Files - Read Them Line By Line And Update Parameters Of The 3rd File ?

Oct 18, 2010

I have two txt files containing x and y coordinates: xcoord.txt & ycoord.txt. I need to open them; read them line by line to get each coordinate; then each time I need to update Xs and Ys parameters inside another file called "dc.in" with the grabbed values.

Finally each time I need to run two exe files ( dc_2002 and st_vac) and produce corresponding output for each Xs and Ys ( dc.in is an input file for this exe files)

I have written the following code but it does not work:

View 14 Replies View Related

Programming :: Using Python To Merge Two Text Files Line For Line

Jul 6, 2010

I'm a bit new to Python programming and hoped that someone might be able to help with a problem I'm having. What I essentially want to do is to combine two text files line for line. I know how to do this in a bash script so to give you a better idea here's the code for that:

Code:

This is basically for adding on values to the end of a CSV file that uses ';' as the delimiter. So say file1 said:

And file2 said:

Then running this command would create merged_file1_and_file2 which would be:

The code I'm using at the moment is:

Code:

As I'm sure any experienced python programmer will see, this prints out the first line of the file "csvraw" and then all of the lines of "stamps" and then the remainder of "csvraw".

What I'd like to do is something like: (pseudo code, I know it's not python ;-))

Code:

Is this possible? I've tried googling and my Python Pocket Reference hasn't been much help. I've looked at pickling but that doesn't seem appropriate.

View 1 Replies View Related

General :: Put Custom Text On Terminal (bash Script)?

Jan 19, 2010

This code:

Code:
#! /bin/bash
echo Okay.
echo
Does not do it....

P.S. I want to show my parents what happens when I do:

Code:
sudo make me a sandwich
and have it say "Okay."

View 11 Replies View Related







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