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


ADVERTISEMENT

Programming :: Join 5 Lines Blocks Comma Delimited?

Nov 26, 2010

I have been searching previous posts but could not find an example which works with my data. I think I might be the spaces in my fields. I have a massive data file and need to join 5 line blocks separated by a comma.

Code:

2
111.222.333.444
host.edu

[code].....

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

Ubuntu :: (BASH) Join Command (GNU Coreutils) - Why Join Ignores The -e Flag And Fails To Insert FOO In The Empty Field

Mar 2, 2011

I am trying to understand the join command. I wish to join two files:

Code:
$ cat test1
a 0
b 2.51
c 19.85
$ cat test2
a 0
b 2.51
[Code]...

this is great but I do not understand why join ignores the -e flag and fails to insert FOO in the empty field.

View 1 Replies View Related

Programming :: Join 2 AWK Scripts?

May 4, 2010

with my question (I�m using Cygwin). How can I join the 2 AWK scripts showed below in a unique script avoiding use temp file?

I have this input file Pipe separated. Code: CATEGORY1|CATEGORY2|CATEGORY3|CATEGORY4
String3|MUSIC/OLDIES/POP/80S/SONGW|String4|
String4|MUSIC/OLDIES/ROCK/70S/SONGX|String5|

[code]....

View 1 Replies View Related

Programming :: How To Write Script That Would Use Join Across All Files In Directory?

Aug 19, 2010

I have a bunch of files that contain a date, then data. When I use join, I get exactly the output I need. But manually joining the first with the second, then that output with the third and so on would take days. I have thousands of files. Can any of you folks help me write a script that would do this?To put it another way, for clarity's sake, here is what I am currently doing

If I were to repeat that 3000 times the final output would be what I need. I know a simple script would do this for me, but I can't figure out how to write it.

View 12 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 :: Command "join" Missing Some Rows?

Apr 30, 2011

Am a bit bewildered on the output of this "join" comad. I'm expecting it to output the 2nd and 3rd columns of both text1.txt and text2.txt. However, it somehow misses some of the columns from text1.txt. For example, rows 1, 2, 8, and 14 are working as expected. The rest of the row aren't.

Code:

cat text1.txt
20110429,10480,Y
20110429,5202,Y
20110429,19434,Y
20110429,19417,Y

[code]....

View 3 Replies View Related

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

Programming :: Displaying Particular Lines Via Grep ?

Apr 8, 2011

So For example I run this command:

Code:

But want to gerp / cut it in such a way that it only displays

Code:

Now the thing is that these 3 lines are not static.. there can be N number of lines there.. the only thing is that I want the command / output NOT to display the first line but the rest of the n lines ..

View 9 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 :: How To Grep Pattern Which Is Split In 2 Lines?

Dec 9, 2010

I need to grep a pattern which can be present in one line or could be split in 2 lines.Normal grep wont work in this case. Can anyone please help on this?There are 100's of files in which i need to search for this pattern so time is also a constrain.

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

Programming :: Bash Calculate The Repeated Lines?

Jan 28, 2010

i have a sorted file with many repeated lines like this:

1ujw
1ujw
1ul1
1us7

[code].....

i need to calculated haw many times each line is repeated, for ex

1ujw 2
1ul1 1
1us7 5
etc.

View 5 Replies View Related

Programming :: Bash There Will Be Empty Lines At The End Of The File?

Mar 26, 2011

Using awk I pull the first field of a random line from my datafile.myvar1=`awk -F" " 'NR=='$randline' {printf "%s", $1}' myfileThis works fine. The problem is there will be empty lines at the end of the file. Rather than using awkto filter out blank lines I would like to figure this out first.So I test $myvar1 for a blank string after setting $randline to one that I know is blank:test -z "$myvar1" && echo "true" || echo "false"But, this returns "false"? So the string is not zero length. Why? It's a tab-separated file. Is awk storing the tab with the $1 field or something.This is where I get headache. I try to echo my variable to see what it looks like.

echo "$myvar1"
outputs: nothing
echo "My variable is [$myvar1]"
outputs: [y variable is [

Why is the closing bracket at the beginning? What character could be stored in $myvar1 that would do such a thing and how did it get there?

View 7 Replies View Related

Programming :: Blank Lines In A Perl Script?

May 4, 2011

there is a way to add line spaces when asking for user interaction in a script. For example:

Code:

SPACE
Hello what is your name?
SPACE
SPACE

So this is asking a question but has a space/empty line at the top of the screen and 2 spaces/empty lines below. I've seen it done in a bash script using for each line/space needed

Code:

echo ""

So what does perl use?

View 5 Replies View Related

Programming :: Display All Lines Before A Match Is Found?

Sep 9, 2010

I have a file, and I have to display all the lines from the beginning of the file till a matching string is found.

I know grep with "-a", "-b" as option does exist, but it needs the number of lines to be printed in advance. eg grep -b 10 "search_string" file so it will print 10 lines before a match is found.

View 3 Replies View Related

Programming :: Find Pattern That Extends Over Several Lines?

Jun 12, 2011

Is there a convenient method to find a text pattern that extends over several lines? In this case:

Empty line
LineConsistingOfSingleWord

Preferably to return the line number where the pattern occurs to determine the first such after a known line number. In other words, in order to extract a block of text from within a file.

View 3 Replies View Related

Programming :: Get Rid Of Unwanted Lines Without Grep -v In BASH?

Jun 9, 2009

I would like to know how I can get the ouput from the following dmidecode command in example 1 to look like example 2 without having to grep -v all the unwanted lines.Is there a way in awk or sed?Example 1

Code:
Processor Information
Socket Designation: Socket 1 CPU 1

[code]...

View 7 Replies View Related







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