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


ADVERTISEMENT

Programming :: Shell Script To Delete Part Text Of A Line If Pattern Matches?

Apr 12, 2010

I am trying to create a shell script, on taking a input file as parameter, which need to do 3 things

1) create a copy of existing file.

2) add a new line to the copied file.

3) strip off all the absolute paths inside the copied file

The first 2 points are straight forward. but i am finding it difficult to acheive the 3rd point. myself not very good with awk and sed. but gave it a shot in vain. For example, the input script consists of below,

PROGRAM=`/usr/bin/basename $0`
HOST=`/usr/bin/uname -n`
echo Start $PROGRAM `/usr/bin/date` |
/usr/bin/tee -a $LOG

The output of the script should look like,

PROGRAM=`basename $0`
HOST=`uname -n`
echo Start $PROGRAM `date` |
tee -a $LOG

View 14 Replies View Related

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

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

Ubuntu :: Sort The Output To A Text File So That It Prints To The Text File At 1 Process Per Line?

Feb 6, 2011

im trying to output a list of running processes via a shell script. At the moment i got this which outputs the processes to a text file called out.

echo $(ps aux) >>out

The problem is though, the processes are all just one big block of text which makes it hard to read. Does anyone know how to sort the output to a text file so that it prints to the text file at 1 process per line? I know its probably simple but im very new to linux.

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

Programming :: Delete A Line From File Using Shell Script?

Oct 16, 2010

i have a file containing contents as

1 2 3
2 2 3
11 2 3

now i want to delete the line which first column content is 1. so, if i pass the parametere 1 to function delete_row. is should remove the first row as

2 2 3
11 2 3

and then write the contents in file.

View 2 Replies View Related

Programming :: How To Append Text To Second Line Of File?

Nov 6, 2010

Say I have a text file like:
Code:
1
3
4
How would I use ksh to put the number '2' into the second line of that file?Okay it's not bash, it's ksh because this computer is OpenBSD

View 14 Replies View Related

Programming :: Updating A Line In A Text File?

Dec 31, 2010

I have a text file called namelist.wps. In this file there is a line that reads:

Code:
start_date = '2010-12-26_12:00:00', '2010-12-26_12:00:00',
I have to automatically update the year, month, and day of month for this line without changing the rest of the file. Here is the script that I have:

[Code]....

View 5 Replies View Related

Programming :: Shell Script To Read A Certain Segment Of A Text File?

Jun 15, 2010

I have a text file that looks sort of like this:

Code:
blah blah blah
tons of unimportant stuff we don't care about

[code]...

View 3 Replies View Related

Programming :: Updating A Single Line In A Text File?

Dec 30, 2010

I have a text file called namelist.wps. In this file there is a line that reads:Code: start_date = '2010-12-26_12:00:00', '2010-12-26_12:00:00', I have to automatically update the year, month, and day of month. I set values for the year, month, and day of month using the following code in a c-shell script:Code: set y1 = `date +%Y`set m1 = `date +%m`set d1 = `date +%d` After I do this, how do I update year, month, and day of month, without changing any of the other lines in the namelist.wps file?

View 2 Replies View Related

Programming :: [Java] Append Something To Each Line In A Text File?

Apr 15, 2009

I am thinking of appending something to each line in a text file with Java. I prefer not write a new file with content appended from the old one.That 'something' would probably be Time Stamp when the file is created (which is same for each line).I am not sure Java provide some easy way for it or not

View 3 Replies View Related

Programming :: Find String In Text File And Add Something To That Line

May 26, 2011

I want to know how can I add something to a specific line.. the output would be something like:
abc
def 123
ghi

Search for string "def" and add something to that line.

View 1 Replies View Related

Programming :: Store Line From Text File Into List C++

Feb 6, 2011

I'm wondering how it is possible to read each line from a text file, and then store each line separately in a list, using C++?

View 2 Replies View Related

Programming :: Shell Script Comparison For Two File(text) Character Wise?

Mar 1, 2010

I need to write a shell script which can compare two files(text files) character wise. eg. underscore is space.

------FILE 1---------------
A_B_C
D_E_F
G_H_I

[code].....

Actual problem: I need to write a shell script which can give me difference character by character not by line (using comm)

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

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

Programming :: Exporting Glade Text View To Text File?

Jan 8, 2011

I want to display something in my text view widget in glade using c code. that's all right.
now I need to attach a save button beneath the text view.so that on click the text view content should save as a txt file..

View 8 Replies View Related

Programming :: Formatting Fields And Text Being Displayed From Text File?

Feb 9, 2011

I want to display the contents of a particular log file (simple text file, I mean in Linux). But there is a problem: The contents need to be organized in a fixed format. Have a look at this log file:

sampleLog.txt

Code:

User Name: XYZ
Reported Problems Description: Blah! Blah! Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah!

[code]....

So, while displaying the contents of above file on a web page, I want to format the field names found in the log file: User Name:, Reported Problems Description:, and Remarks:. These fields may contain a variable length of text and no specific line number is assumed for them to appear on.

The desired output should look like this:

User Name: XYZ
Reported Problems Description: Blah! Blah! Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah!

[code]....

Well, what I am trying to do may sound wierd to some of you. The filed "Reported Problems Description:" can possible contain text which embeds colon (.

View 15 Replies View Related

Programming :: Remove Lines In A Text File Based On Another Text File?

Jan 28, 2009

I have a text file called file1.txt containing many lines eg.

line1
line2
line3
line4
line5
line6

Then i have another text file called file2.txt contains

3
5
6

Is there a command to remove the lines in file1.txt based on the keywords in file2.txt? note: It should remove line3,line5,line6 based on 3,5,6

View 10 Replies View Related

Programming :: Reading In A Outside Text File And Putting In The String On That Line Into A Char Array That Is Already Allocated?

Mar 29, 2011

Here is the issue. I am reading in a outside text file and putting in the string on that line into a char array that is already allocated.

Code:
int main(int argc, char *argv[])
{

[code]....

View 1 Replies View Related

General :: Replacement On More Than One Line In Text Files Using Shell

Nov 25, 2010

How can I replace one instance of a word in a text file with a piece of text that spreads several lines ? I know sed or awk is the way to go but don't know that how I can introduce new paragraphs using these tools

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

Programming :: Search A File For A Particular Pattern And If Pattern Found Replace The Line With New Text?

Feb 24, 2010

I want to search a file for a particular pattern and if pattern found replace the line with new text. i am using awk 'match($0,"pattern") != 0 {print $0} ' filename to check if the pattern exists.how do i get the line number of the pattern and delete that line and replace the line with my new text?

View 1 Replies View Related

Programming :: Text On A Specific Line At The End Of A Line?

Jul 26, 2010

I'm trying to add text to a file for a specific group of users, I'll need to do examples as I can't think of an easy way of explaining, my file is like this:

Code:

users{
user1
user2

[code]....

At the present my code lists all the available groups, how would I add a user to a specified group? (e.g add "members user3") to the end of group 1 for example. So the code ends up like this

Code:

members user2,user3

View 14 Replies View Related

Red Hat / Fedora :: Edit A Text File To Delete All Commas In The File?

Jan 4, 2011

i want to find a command line way to edit a text file to delete all commas in the file. i do not want to replace them w/ anything.

View 2 Replies View Related

Ubuntu :: Delete All Files Listed In A Text File?

May 26, 2010

Through various Windows reinstalls and switches within Linux distros, I have a massive amount of duplication within my music archive (on the order of 7+ dupes of each file). Now, I found a lovely program called "fdupes" and was able to build a list of all the duplicate files, and I'm trying to use "xargs" to remove then. However, when I try and run the command "xargs -0 --arg-file="dupes.txt" rm" or "xargs -0 rm < "dupes.txt"" it give me the following error: "xargs: argument line too long".

how perhaps a different way of accomplishing the same thing?

View 9 Replies View Related

Software :: Delete Top Lines Of A Text File Until A Word Is Met?

Jul 7, 2011

I need to chop of the top 30ish lines of several log files until a line starting with "Initialization completed."The trouble is that it's not always the same amount of lines that need to be deleted, and they don't always contain the same information, which is why I would need to delete everything priorhe line starting with "Initialization completed."Right now I have a little script I wrote based on looping each file through several "grep -v" commands with each known pattern of lines I want to ignore, but it is tedious and I have to inspect each file afterwards to make sure nothing is left from above "Initialization completed

View 3 Replies View Related







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