Programming :: Awk - Summing Over Specific Lines?

Mar 31, 2011

I'm struggling myself with this problem: I have a file which contains a single column of data

2
.
.
.
45

[code]...

Is there a way to do it with awk?

View 7 Replies


ADVERTISEMENT

Programming :: Reading Specific Lines From A File?

Sep 10, 2009

To save on the writing of WAY to many files with very little in them, I want to put it all in one file and read a specific few lines. There will be six variables to be read at a time. Format is as such:

//Set 1
string name
5
12

[code]....

From name to 5th number is a set. The name will be of different lengths for each set. This will be a big file of probably 40+ sets. My problem lies in reading one and only one set be it set 5 or set 34. It needs to be done in C++.

View 2 Replies View Related

Programming :: Remove Specific Lines From File

Jan 21, 2011

I'm trying to come up with ideas for a simple way to strip a specific "entry" from a text file.I know tools like sed and perl can remove specific lines from a file but I haven't been able to come up with an elegant way to do my group of lines.In my file, the first "Location" line and the "SVNPath" line should be unique every time... but are they enough to strip out the whole set of the group plus the trailing one line of white space separating each group? Add to this, my file will grow as new entries are added (always appended to the end) but new entries will have the same formatting.

View 9 Replies View Related

Programming :: Extract Specific Lines From A Flat File?

Mar 10, 2011

I'm trying to extract specific lines from a flat file. I need lines that fall within a range of coordinates. The -F can be either ! or = If the line is in this set range I need all of the data on that line. ranges lat 36 to 39 and longitude -74 to -84

awk -F '=' '{lat=substr($2,1,2); lon=substr($2,10,3); (lat >36 && lat <39) && (lon >-74 && lon <-84); print lat"--"lon}' < net.log

example line from the flat file
K4MQF-3>APN383,VA2-2,qAR,N3HF-5:!3818.65NS07800.17W#PHG77306/W3,VA3/Clarke Mnt

View 9 Replies View Related

Programming :: Deleting Lines From A File With Specific Pattern Using AWK?

Jun 6, 2010

I have a file which contains milion of records. It contains 12 columns seperated by "||" (delimeter).

First two fields contain first name and last name of a person. Now my requirement is to delete all those records from this file for which:

First two fields does not contain any alphabet.

For e.g i have below mentioned records in file:

gaurav||gandhi||123||456||789
#a%bcd||123abc||89|90||91
12345||@@@||89||123||234
***||!!!!||98||76||90

Now, last two lines should be removed from this file since first two fields does not contain any alphabet for these two records.

View 12 Replies View Related

Programming :: Replace Pattern In Specific Lines And Column With AWK?

Apr 24, 2010

Im tryng to replace in specific column and line number within a file where its 3erd column contain the same string in all lines.

[code]....

My goal is to replace only first and last ocurrences of "Normal player", with the following desired output:

[code]....

Im not sure how to use the "IF" and "AND" conditions together. I�ve tryed with the code below, but the script replaces the string for every line.

[code]....

how to replace values for specific column in first and last lines within same AWK script, without taking reference data in other columns?

View 10 Replies View Related

Programming :: Bash Script To Count Number Of Lines With A Specific Property7?

Aug 11, 2010

I would like to parse an input file in which there are two columns per each row. We want to see how many lines are duplicated where we define duplicate to be having the same second field and different first field. For instance if the input file looks like the following:

79874 13131
79873 12309
79820 13131

[code]...

View 10 Replies View Related

Programming :: Substitute Few Words + Change All The Lines Starting With A Specific Word + Put Blank?

Jan 17, 2009

I have an old-address-list file which is having around 1500 entries. I need to convert this addresses in to a specific format.

The old-address-list file>
# cat old-address-list-file
dn: CN=Muhammad Hadhi K.M,OU=IT Dept,OU=Example Company H.O,DC=example,DC=com
cn: Muhammad Hadhi K.M

[code]....

View 6 Replies View Related

Programming :: Remove Lines And Parts Of Lines From Python Strings?

Nov 24, 2009

How do you remove parts of strings using python? Such as, if I have something like:

Code:
erme1 sdifskenklsd
erme2 sdfjksliel

[code]....

View 3 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 :: Sed - Replacing Only Text With Several Specific Lines Excluded

Jun 17, 2010

As much as I didn't want to ask a sed question, especially considering there's already one on this page I've looked as best I could and cant find the solution. Id like to use sed to replace occurrences of a pattern but exclude two or 3 specific lines that are not consecutive. For example I know with 1,10 i could exclude the first 10 lines, what is the syntax if I just wanted to exclude line 3 and 7. The sed command I'm working with right now is for rearranging Ethernets.

cat /etc/udev/rules.d/70-persistent-net.rules | sed -e '/'"$found1fullmac"'/!s/eth1/'"found1eth"'/' > /etc/udev/rules.d/70-persistent-net.rules

I would like to replace $found1fullmac with two variables representing line numbers to exclude from the replacement.

View 6 Replies View Related

Software :: Printing Specific Lines Of File Using Script

May 19, 2009

I have text file with say 1000 lines.And I want to display lines numbered 100, 203 and 297 using a script/ command.How can I do this ?I can print a particular line using:sed -n '100p' file1 (where file1 is input file).

View 6 Replies View Related

Programming :: Search A Bunch Of Files In A Specific Folder For A Specific Number?

Jul 24, 2010

I need to search a bunch of files in a specific folder for a specific number and add all the numbers together to a total sum. I use Rsync everyday, everytime I run rsync i get a logfile (rsync output) witch contains the textstring "Total bytes sent: xxxxxx".

The "xxxxx" can vary in lenght. I need to extract the "xxxxxx" from each file and add the numbers together to a total size over a week or a month. Is this possible? And I wish to only use bash. One way of doing stuff at a time my friends .

View 5 Replies View Related

General :: Display Specific Block Of Contents Or Lines In Output?

Apr 23, 2010

Consider a situation in which you want to display only specific lines of contents from a file or of a command's output. Yes, we have head and tail commands. But, how to view all the lines of a file except the last one or vise versa when we don't know the count of lines in advance?

Consider this output:

Code:

[root@localhost ~]# ps au | grep bash
root 6316 0.0 0.0 4672 1440 tty1 Ss+ Apr22 0:02 -bash
root 20847 0.2 0.0 4672 1432 pts/0 Ss Apr23 0:12 -bash
root 21167 0.0 0.0 3920 660 pts/0 S+ 01:00 0:00 grep bash

Here, I don't want the last line (in italic) to be included in the result since the last line is due to "grep bash" in the devised command "ps au | grep bash". Well, we can rewrite the devised command:

Quote:

"ps au | grep bash | head -n 2"

But, again, here we are specifying the count of lines to be included. But, in the presented problem we don't know any count in advance!

View 6 Replies View Related

Programming :: Replace Specific Character After Specific Line By Awk?

Jul 19, 2010

I want to replace specific character in a file after every specific line. example as follows.

O 000000000000000000
A 111111111111111111
C 222222222222222222

[code]...

View 2 Replies View Related

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

General :: Summing Durations From A Text File?

May 19, 2011

little bit of pipe action and using mediainfo I was able to create a text file with the durations of recordings in the following format:

Code:
Duration : 13mn 16s
Duration : 1h 57mn
Duration : 1h 33mn
Duration : 47mn 1s
Duration : 45mn 51s
Duration : 2h 13mn
...etc

I'd like to know just long all of this is. I was originally thinking of doing several sed commands creating additional text files from the 'h' 'mn' and 's' throughout, but I feel like that's creating more work for myself than it needs to be. I feel like awk should do this,

View 2 Replies View Related

Programming :: Command To Run Another One On Few Lines

Jul 23, 2010

Is there a command which can be used to run some other command on a few lines from a file or an o/p of some file. (the kind of role that -exec option does for the find command). (I have solved the purpose using a bash loop but would like to know if there exists a command).

View 4 Replies View Related

Programming :: Awk - Get A Block Of Lines?

Apr 23, 2010

I tried to get a block of lines in awk, but unfortunately it returns output of one line only. I don't state the code here, because it's too short and too poor. What exactly I wanted to do: from file "/boot/grub/menu.lst" get blocks of lines, starting by title and ending by Now I have just

Code:

script="/boot/grub/menu.lst";
OLDIFS=$IFS; IFS=$'
';

[code]....

I want to get every block as one row of array.

View 14 Replies View Related

Programming :: Take A Int From 2 Lines Of Text?

Apr 20, 2011

I do a logcat, i got lot of lines, that I filter with a grep, at end, I just got some lines like this:

Code:
I/ActivityManager( 1763): Config changed: { scale=1.0 imsi=732/123 loc=es_ES touch=3 keys=2/1/2 nav=2/1 orien=1 layout=17 uiMode=17 seq=15}

[code]...

View 6 Replies View Related

Programming :: Remove All Lines Containing 'A,,,,,,?

Nov 3, 2010

How can I remove all lines which contain A,,,,,, I tried the following sed statements but no luck.

Code:

sed "/A,,,,,,/d file"
sed "/A,,,,,,/d file"

View 6 Replies View Related

Programming :: Three Lines Of Code - What Do They Actually Mean

Feb 23, 2011

whichever source code I go through I find these three lines of code written what do they actually mean and what is their function?

[code]...

View 6 Replies View Related

Programming :: AWK: Join Lines If NF Is Wrong?

Jul 1, 2010

I have a large CSV file, tab-delimited with CRLF at the end of each line. Each line should contain 5 fields (i.e. NF == 5) However, there are rogue CRLF characters in the middle of some records, causing records to be split across two lines. I want to scan each line, check the field count and if it's !=5 then join that line to the following line. Example input might be;

Code:

one two three four five
six seven eight nine ten
eleven tw<CRLF>
elve thirteen fourteen fifteen

[code].....

View 2 Replies View Related

Programming :: CSS - Put Several Lines Of HTML Into One Line Using CSS?

Dec 14, 2008

I've got a website set up which has a section which is just a bunch of links on the side. But this section of links is on every page of the website. And when I expand and add more links I don't want to have to go to every page and add the new link. Is there a way that I could put all the links into something on CSS (or anything else) that I could just include one line in the HTML? So that when I add a link I'll only have to edit the one file and and then every page will be updated?

View 12 Replies View Related

Programming :: Delete Lines Between Match?

May 15, 2011

My problem is like this I have to delete all lines between two pattern match example- suppose below is the content of the file then i have to delete all lines between text1 and text2

...
text1
abc
def
ghi

[Code]....

View 14 Replies View Related

Programming :: Deleting Lines Above And Below A Word

Mar 25, 2011

i jst want to delete a host entry from httpd.conf the entry for lal.com should be deleted!!

View 14 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 :: List 10 Lines By Same In Bash?

Mar 30, 2010

I have a file witch I need to list 10 line by 10 lines with something like press enter to go on in between.
Well, the problem is that i have absolutely no idea on how to implement this.

Can you give me some points?

View 3 Replies View Related

Programming :: Modify Lines That Are Too Long?

May 25, 2010

I have a CDL netlist with 5630 lines. 512 of the lines are over 128 characters. The tool I am using to read in the CDL returns an error for each line over 128 characters.

If the line is too long I can fix it by adding a line continuation symbol, in this case a "/", somewhere prior to the 128th character then a line feed, obviously, and a "+" to the continuation.

example (pretend its a long line);
before;
this line is too long
after;
this line /
+ is too long

Part of the problem is that I can't use a constant point prior to the 128th character because I can't break up a term.

bad;
this line i /
+ s too long

If I can replace the last space before the 128th character with " / + " on all lines that are over 128 characters then I'm golden. I'm not sure if I need to escape the + or not. If so then the substitution is " / + ". And if I use sed then I'll escape the .

View 6 Replies View Related







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