Programming :: Copy Lines From Multiple Files To One File Using Sed -w?

Aug 25, 2010

I've been trying to sort this out for several hours and I?m totally lost? I?ve been searching around, but haven?t found the solution to my problem. I have a directory with 100 files. I need to copy 10 lines of each files (let?s say from line 45 to 55) into one unique file. So I guess I could use sed ?w, but I didn?t manage to write the right script. I also tried using a loop to create 100 different files, each one with the 10 lines) to concatenate them later on. But I only got 1 file, not 100.

View 12 Replies


ADVERTISEMENT

General :: Copy Lines Starting And Ending With Specific Pattern From Multiple Files To A File?

Jul 27, 2011

A function by name abc is called in many files. I want to copy all the lines with the function call to an output file.A simple grep on function name doesn't help me as the function call is spanning across multiple lines as follows:

abc(parameter1,
parameter2,
parameter3);

So I want to copy all the three lines (till semicolon) to the output file.The problem is because there are more than 200 calls for the same function and I cannot do it manually

View 2 Replies View Related

Programming :: Read Multiple Lines From A Text File?

Mar 11, 2011

For example, I have a text file with data which lists numerical values from two separate individuals

Code:
Person A
100

[code]...

View 1 Replies View Related

Programming :: Deleting Multiple Lines Above And Below Expression In File

May 19, 2010

I have a very, very large log file (360MB) that I'm trying to thin out. As it turns out the majority of this file has entries that aren't necessary so I'm attempting to build a command that will strip these out. The following command works to display only the data that I do not want:

Code:
cat xml_results.log | grep -B 6 -A 5 "YYY ZZZ"

This displays exactly the data I want to delete from the file by displaying the expression and six lines above it and five lines below it. However I'm at a loss as to how to remove this data from the output and display everything else. I looked into the -v option with grep redirecting the output to a new file:

Code:
cat xml_results.log | grep -B 6 -A 5 -v "YYY ZZZ" > xml_filtered_results.log

However it doesn't work, the new file is the same size as the old one. What am I doing wrong? Is there a better method of doing this? I'm a bit out of my element since the method I'd normally use can't handle files of this size.

View 7 Replies View Related

Programming :: Delete Multiple Lines In A File Using Perl?

Apr 15, 2011

I have a file looks like the following:

digraph topology
{
"192.168.3.254" -> "10.1.1.11"[label="1.000", style=solid];
"192.168.3.254" -> "10.1.1.12"[label="1.000", style=solid];

[code]...

Order of these lines are random... So I cannot delete line #19, for example... And you can see that top four lines I want to delete are pairs. So there might be some clever way to detect the lines, if a line has both "1.9" and "1.11", then delete the line... I am new to perl language. The following is the code I have now... I think I just need to write some code inside the while loop checking if I want to delete the line $dotline before I write to a NEW file.

Code:

#!/usr/bin/perl -w
$TOPPATH = "/tmp";
$NAME = "topology";
$FILENAME = "$TOPPATH/$NAME.dot";

[code]....

View 16 Replies View Related

Programming :: (BASH) How To Read Multiple Lines From Text File

Mar 11, 2011

For example, I have a text file with data which lists numerical values from two separate individuals

Code:
Person A
100
200
300
400
500
600
700
800
900
1000
1100
1200

Person B
1200
1100
1000
900
800
700
600
500
400
300
200
100

How would I go about reading the values for each Person, then being able to perform mathematical equations for each Person (finding the sum for example)?

View 13 Replies View Related

Programming :: Bash Script To Find And Remove Similar Lines From Multiple Files?

Jun 5, 2009

I want to remove duplicate or multiple similar lines from multiple files. I.e. if I have four files file1.txt file2.txt file3.txt and file4.txt and would like to find and remove similar lines from all these files keeping only one line from these similar lines. I only that uniq can be used to remove similar lines from a sorted file.

View 9 Replies View Related

Programming :: [Perl] Fail To Sort A File With 300,000 Lines By Multiple Columns?

Nov 10, 2009

Each line of the file I am sorting is in the following format:

<url> <month> <day>

For example:

[URL]

I wrote the following to sort:

Code:

#!/usr/bin/perl
$in = shift;
chomp($in);

[code]....

The script worked fine for my small testing files, but failed in my input file. The input file is 18MB and containing more than 300,000 lines. The output will contains some lines like that:

url_one 10 1
url_two 10 1
url_three 10 3
url_four 10 1

Is that because my file is too big for perl to handle ?

View 10 Replies View Related

Programming :: Copy One File Content To Multiple File

May 28, 2010

I wanted to copy one file to multiple new files. I have an idea to write a script and do the operation. But here i m looking for any particular command to do this operation.

View 1 Replies View Related

Ubuntu :: Replace Multiple Lines In Multiple Files?

Aug 20, 2011

I often use the rpl command to make changes to multiple html files at once. For example:

rpl -R '<br />' '<br /><br />' mydirectory However, I haven't been able to figure out how to change multiple lines. For example, let's say I want to change all occurrences of :

<br />
<br />
to:
<br />
I've tried
rpl -R '<br />
<br />' '<br />' mydirectory

but that didn't work. how to do this with rpl or some other way?

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

Programming :: Inserting Multiple Lines - With Newline - Using Sed Or Awk

Mar 8, 2009

I need to replace part of a line in a file with multiple lines, however need to separate each line with a newline is this possible?

Example, need to remove line 2

And insert line similar to below:

If the multiple lines were part of a text file, would inserting a text file automatically include newline characters?

View 1 Replies View Related

General :: Script To Append Lines To Multiple Files?

Aug 22, 2009

eed to make a script to append a line to the bottom of multiple files (only certain files, but 100's spread over directories).Doing a find replace inside multiple files is easy, I use the followingfind /base/dir -name "*.txt" -exec perl -pi -w -e 's/FIND/REPLACE/g;' {} ;So I tried doing the followingfind /base/dir -name "*.txt" -exec echo "Append this" >> {} ;However this just appends all the text into a file called "{}". Whereas {} should be replaced with each file that's found.

View 1 Replies View Related

Ubuntu :: Select Lines Containing Word And Copy To Another File?

May 31, 2011

I am trying to find a way to search a text file for a certain keyword and then select each line containing the word , copy and paste these lines into another text file. I can do this easily with UltraEdit but I cannot figure out how to do it in Jedit or Scite.

View 5 Replies View Related

Programming :: Unable To Match Across Multiple Lines In Perl

May 11, 2011

I'm trying to split a text file into various parts. Everything in between "123" and "break" (including linebreaks) goes into the splitted file.

e.g. using this text file:

This should split into 4 files. However I'm only getting 2 files: one for the line "123break" and one for "123 blah break". The two occurrences that contain linebreaks are being ignored. The .* part of my match should capture linebreaks seeing that I'm using the /s modifier shouldn't it? Even when I use the match /(123 break)/gs it still doesn't capture the first occurrence. I'm using Perl v5.12.3 (from ActiveState) on Windows XP. The text file is also in Windows format.

Code listed below.

The above code generates two files Output_1.txt and Output_2.txt which contain "123break" and "123 blah break" respectively. I want it to generate four files.

View 4 Replies View Related

Server :: Remove Dynamic String Across Multiple Lines And Files?

May 13, 2011

My server was hit with an injection script which has placed code across many of my clients files. I need a script that can remove a block of php code that spans multiple lines, multiple directories/files and is dynamic, meaning that part of the code changes. I think using find/sed is what I need but cannot seem to figure out how to get it to work.The following is the script that is being injected everywhere. The catch is that they have generated dynamic code at the start/end of the script. (I have commented the parts that are dynamically changing on EVERY instance).PLEASE NOTE: Directly following this script is the start of a valid php script that I do not want to delete.

<?php
//{{65281980 - DYNAMIC!!
GLOBAL $alreadyxxx;

[code]...

View 2 Replies View Related

General :: Creating A Script To Move Or Copy Files Into Multiple Directories Below The Files?

Aug 25, 2009

How can you create a script to move or copy files from a main directory into multiple directories below the main directory.

View 7 Replies View Related

Programming :: Perl Regex Not Matching Across Multiple Lines Despite Ms Flags / Fix It?

Aug 16, 2010

I have written a regular expression (tested in regexpal and regextester alpha something) with which I want to replace something like code...

but it only matches functions which occupy one line only, despite my tests showing multiple line matching in javascript testers online and using the m and s flags (which should make it multi line no?)

View 14 Replies View Related

OpenSUSE :: Count Lines In Multiple Text Files From Command Line?

Apr 27, 2010

I want to (from the command line) be able to counte lines in a bunch of files of a specific type in a folder and all its sub-folders. How would I do this?

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

OpenSUSE :: Web - Screen Loads And After Initial First Few Lines Breaks Up Into Multiple Repetitions Of Lines

Apr 22, 2011

I have been experiencing a problem where the screen loads and after initial first few lines breaks up into multiple repetitions of lines. Reloading helps but has to be repeated when pageing down. Mail is no problem; it is supplied by my network provider. OS is openSUSE 11.2 which I update when advised. Below is a sample from the error console:

[Code]...

View 1 Replies View Related

Software :: Copy Files From One Source To Multiple Destination Simultaneously?

Aug 5, 2010

i want to copy one or more files or directory from one drive to multiple drive simultaneously. It like a cloning a disk. But i dont like clone entire disk. i want to copy/clone only certine files or folder. if any one can know how to copy one source to multiple destination simultaneously.

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

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

Ubuntu :: When Drag The File To Install It Again It Says Something Along The Lines Of It Cannot Copy A Directory Over A Directory?

Feb 19, 2010

I downloaded a mouse theme form gnome look and installed it in the themes. But it has not appeared in the pointer themes section in custimation even though it said that it is installed correctly.When I drag the file to install it again it says something along the lines of it cannot copy a directory over a directory.Where can I find where the mouse/pointer theme is located and delete it. I have searched filesystem, google and these forums and not had any luck yet.

View 1 Replies View Related

Programming :: How To Add Characters And Lines To File

Jan 29, 2011

For example, I have a file called "file" like this one:
type=strongsubj len=1 word=absolve pos=verb stemmed=y priorpolarity=positive
type=strongsubj len=1 word=unique pos=adj stemmed=n priorpolarity=neutral
type=strongsubj len=1 word=absolutely pos=adj stemmed=n priorpolarity=neutral
type=weaksubj len=1 word=taking pos=verb stemmed=y priorpolarity=positive
type=weaksubj len=1 word=friend pos=noun stemmed=n priorpolarity=positive
type=weaksubj len=1 word=usually pos=adverb stemmed=n priorpolarity=positive
type=strongsubj len=1 word=purecolor pos=anypos stemmed=n priorpolarity=negative
type=strongsubj len=1 word=accusingly pos=anypos stemmed=n priorpolarity=negative

I want to add the plural for the noun, for example if find this line:
type=weaksubj len=1 word=friend pos=noun stemmed=n priorpolarity=positive
will add one more line :
type=weaksubj len=1 word=friends pos=noun stemmed=n priorpolarity=positive
where we add "s" for the word friend
I did try to do like that:
<code>
cat file | while read LINE ; do

set -- ${line}
if [[ "${4#pos1=}" == "noun" ]];then
#I tried this line but it doesn't work properly:
v3==$(echo $line |sed 's/$3/$s') #I want to find the third word "word=friend" in that line and add "s" after that word
# I don't know what command to add this new line "$v3" to the file ???
done
</code>

View 12 Replies View Related

Programming :: Indent The File Lines Using Vi?

Oct 1, 2010

Every now and then I have to indent the lines in my script to 4 space characters. I generally do it line by line. Is there an automated command in vi using which I can indent some set of lines to desired number of space characters in one go.

View 5 Replies View Related

Programming :: Sed Match Last X Lines Of A File

Mar 17, 2009

I'm trying to find the correct sed syntax to match from a given pattern to the end of the file and then append that pattern to the end of the file.

I was trying:

But that prints each line right after its original occurrence. I want to match the block and then append it to the end of the file.

View 12 Replies View Related

Programming :: Bash Script To Copy All Music To New Hard Drive From Multiple Network Shares

Aug 9, 2010

I need a script to copy music from a network drive to my local disk. I require the script to auto mount the remote server, then to create the directory path to the mp3's I have a list of all teh songs in the following format, note some have spaces.

\7800SPARE4UsersPublicMusicSample MusicKalimba.mp3 \7800SPARE4UsersPublicMusicSample MusicMaid with the Flaxen Hair.mp \7800SPARE5UsersPublicMusicSample Song Sleep Away.mp3

I can use the following to mount the directory:

mount -t cifs //7800SPARE4/Users /dest-o username=user,password=pass

I'm thinking the best way would be to get the share name 7800SPARE and the grep for all these in the list, then mount it and do a while read LINE However I would need to creat the folders, I am unsure on how to do this. I think I would need to sed the backslashes to forward ones and then use rsync? Then unmount and move on to the next ones, if I can't mount the share It would be nice to log it and skip it.

View 2 Replies View Related

Programming :: Add Comma To End Of Lines In Text File?

Aug 21, 2010

I have a plain text file with 360 lines of varying length text. How do I add a comma or other symbol to the end of each line so that I can convert the file to csv format that I can open in a spreadsheet (45 rows, 8 columns). That means each 8 lines of text forms 8 columns, with 45 rows.

View 9 Replies View Related







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