General :: Replace Several Lines In A File With Other Lines In Another File?

Oct 26, 2009

I have this massive table file with some data in it and I want to replace some lines that are wrong with the correct ones that are in another table file of the same format. The wrong lines are not all together in a block but randomly distributed so I need to make a loop checking if the line is in the other file and if it is, replace it. I want to try and do it with sed or awk but I don't really know how to....

View 12 Replies


ADVERTISEMENT

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 :: View A Particular Ten Lines In A Large File Where Can't Open The File In Vi

May 12, 2010

I am using RHEL 5.I have a very large test file which cannot be opened in vi.The content of the file has some 8000 lines.I need to view ten lines between 5680 to 5690.How can i view these particular lines in a large file.what is command and option i need to use.

View 1 Replies View Related

General :: Removing Lines From A File That Are In Another File?

Jan 6, 2011

I have a large text file containing over 180k lines and another text file containing about 1k. I would like to remove lines in the 180k-line file that exist in the 1k-line file.

View 5 Replies View Related

General :: Add Characters To Several Lines In A File?

Apr 17, 2009

I would like to modify the content of a text file in Linux, in the following way:=> the file has several of these lines:./run_pest3 ./g134366.04080_0.062 x 2_d043 1 0.43 results_EC=> I want to modify all lines to be:./run_pest3 ./g134366.04080_0.062 x 2_d043 1 0.43 results_EC0.062i.e., the last number of $2 should be "attached" to the end of $7, for each line.

View 5 Replies View Related

General :: Extract Lines From File Using AWK ?

Aug 5, 2010

I have a file similar to this:

I need to print the last line for each user into a file. The resulting file should look like this:

Is there a way that AWK can match lines from $1 and then print the last line into a file?

View 7 Replies View Related

General :: Adding Lines Of A File Together?

Feb 22, 2010

I'm trying to output two certain fields of a very large text file to 2 very small text files. Then take those files and add all the lines together to come up with a total from each file (two totals).

Here's what I've got:

Code:

#!/bin/bash
echo "0" > /media/in.txt
echo "0" > /media/out.txt

[code]....

Breakdown: Put 0 in a text file to be drawn by respective while loops for math later

Output last 60 integers to a file for total A (new integer every minute)
Output last 60 integers to a file for total B (new integer every minute)

The two while loops are supposed to be adding the lines together. The echo commands at the end are for testing purposes, just to see the output. However, when I run this, I get the output of

Code:

0 0

Which is obviously not what it's supposed to be. Is there a more efficient way to do this or am I missing something in the script that would reset the values to "0"?

View 2 Replies View Related

General :: Delete Last 6 Lines Of File With Sed

Jun 5, 2011

looking to delete the last 6 lines of a file with sed. figured out how to delete the last line..but i want the last six.

View 6 Replies View Related

General :: Add A Line In A File Before The Last Two Lines?

Aug 2, 2010

I need to add a line in a file before the last two lines using a script using standard linux editors like sed but i can't figure it out.

View 2 Replies View Related

General :: View File Ignoring Set Of Lines?

Jun 21, 2010

I'm having a file with repeated particular text lines. So I need to view the file content ignoring these lines. Is there anyway I can achieve this using VI

View 2 Replies View Related

General :: Conditionally Deleting Lines From File

Mar 10, 2011

I am facing some problem regarding deletion of a line from a text file. The file consists of the lines of type which consists of more than 6 occurrences of : character in it. The line should be deleted completely and the line next to it must be shifted up.

View 1 Replies View Related

General :: Copy Some Lines In A File And Delete These After?

Jul 20, 2010

I have a file that contains 100 ligns, i need to write a script that read 70 lignes and redirect those 70 ligns to another files and these 70ligns have to be erased in the first file

when i write this command
head -70 somefile.txt>test.txt
or

sed -n 70p somefile.txt>test.txt

i have these 70 lines in the text.txt files
but these 70 lines have to be deleted inthe first file somefile.txt

View 1 Replies View Related

General :: Split A File Into Two - The First Being The First Two Lines And The Second The Rest?

Nov 1, 2010

I'd like to split a file into two, where the first file is the first two lines and the second is the remaining lines (third line to EOF).

View 2 Replies View Related

General :: Delete Lines From File By Their's Length

Apr 27, 2010

i've got a file with sorted words - one on each line.How could it be possible to delete thouse lines that have words of length 1 or 2 (1-2 letters). I guess a good way it will be with AWK, n its fuction length(), but getting it, i dont know how to delete those very lines.

View 14 Replies View Related

General :: Grep And Store Two Lines In Other File

Feb 16, 2011

I have following contents

I want to grep "#2" and want the output as

How to using shell script?

View 6 Replies View Related

General :: Remove All Lines In A File Containing Sameword?

Aug 6, 2010

When i want to remove particular lines containing a specific word in from entire document at a time,i am using the following command.

awk '$columnno !~/specificword/' inputfile > outputfile

But here, coulmn no is my problem, because iam having this in different columns. So i need a solution for it.

How to write such removal command without mentioning column no. , ie irrespective of column no, it has to remove all lines having that specific word.

View 10 Replies View Related

General :: Use AWK To Print Out First Few Lines Of A Text File?

Jul 27, 2011

I have a few rather large text files, and I need a way to look at the first three lines of each. Is there a way to do this using awk?

View 3 Replies View Related

OpenSUSE Network :: Add Few Lines To Php.ini File And Modify Suhosin File?

Dec 29, 2009

Is installing "php5-suhosin" from yast and restarting apache enough to make suhosin work out of the box? Or do I need to add few lines to php.ini file and modify suhosin file?

View 3 Replies View Related

Ubuntu :: Netbeans - Whenever The File Contains More Than 3000 Lines,the File Is Not Readable?

Mar 4, 2010

HI am facing the strange issue in netbeans on ubuntu 9.04. whenever the file contains more than 3000 lines the characters overlap on each other and the file is not readable, where as if the file is less than 3000 lines it works fine. what may be the reason ?

View 2 Replies View Related

Programming :: Sed Delete Lines From File One If Regexp Are Listed In File Two?

Sep 17, 2009

I am trying to delete lines of a file if they contain text that is present on another file. For example

> cat one.txt:

a
b
c
d

[code]....

I get the following output:

> ./test.sh one.txt two.txt
a
b
d
e

[code]....

View 6 Replies View Related

General :: Grep Multiple Lines From A Text File

Jun 17, 2009

I have a list of words that I want to grep in many files to see which ones have it and which ones dont. in the text file I have all the words listed line by line, ex: list.txt:

check
try this
word1
word2
open space
list ..

I want to grep each line one by one. like I want it to

grep "check" *.log
grep "try this" *.log
grep "word1" *.log .. etc how can I do this?

and maybe write the output to a file.

View 5 Replies View Related

General :: Command To Swap Even And Odd Numbered Lines In A File

May 28, 2010

I'm looking for a command to swap the even/odd numbered lines in a file. Example input file:

Code:

1
2
3
4

[code]...

Example output file:

Code:

2
1
4
3

[code]....

I'm sure there's a way to do it with sed, awk, grep and the like but it's been many years since I've used these commands on a daily basis and I can't seem to figure out the correct syntax.

View 2 Replies View Related

General :: Commands To Remove Particular Few Lines In History File?

Jun 16, 2010

Is there any commands or scripts to remove only selected line in the history file.

View 1 Replies View Related

General :: Delete All Lines In A File Which Consists Of Particular String?

Mar 21, 2011

i am having following lines in a file called test.

subscribe parser for dinesh
extend size for dinesh
subscribe parser for anish
unsubscribe parser for dinesh
extend size for arvind

I want to delete all lines which contains the string "dinesh". Is it possible.

View 8 Replies View Related

General :: Show Specific Lines In A Text File?

Feb 3, 2011

I have created a text file in Linux, and I only want to show certain users. Here is my text file:

usr user tty Limbo?
11 12:06:13 APW no
12 12:06:13 APW no

[code]...

View 12 Replies View Related

General :: Remove Lone Lines From A Text File?

Jul 6, 2011

anyone has ideas how to remove lone lines from a text file?

If I have a file that is like this:
-----------------------------------
line 1

[code]...

View 14 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 :: Removing Blank Lines And Commentary From A Config File?

Aug 18, 2010

I am currently using a command like this to remove blank lines and lines which contain (not necessarily begin) with a #. Is there a better/simpler command?

cat /etc/apache2/default-server.conf | sed /^$/d | grep -v '#'

View 15 Replies View Related

General :: Script To Read And Compare Two Consecutive Lines In A File?

Jan 18, 2011

I have a file like below

ADP_Comment- 4758
ADP_Comment-is missing
cbdkbckd- 46983

[code]...

View 15 Replies View Related

General :: Remove Lines From A Syslog Text File That Have Duplicate Strings

Mar 17, 2011

Trying to remove lines from a syslog text file that have duplicate strings

Mar 10 06:51:11[http-8080-1] INFO com.MYCOMPANY.webservices.userservice.web.UserServiceController [u:2533274802474744|360] Authorize [platformI$tformIdAndOs=2533274802474744|360, userRegion=America|360]

then a few lines down

Mar 10 06:52:03 [http-8080-1] INFO com.MYCOMPANY.webservices.userservice.web.UserServiceController [u:2533274802474744|360] Authorize [platformI$tformIdAndOs=2533274802474744|360, userRegion=America|360

got the same thing in terms of a u: number but the issue is I need to remove duplicates and just leave one and the file has multiple duplicates of different u: numbers and it's 14,000 lines long. can anyone tell me if I can use awk? sed? or sort for something like this to? removing lines that have a certain string in there that's a duplicate.

View 4 Replies View Related







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