Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to remove first field of the next line? Post 302967038 by Don Cragun on Friday 19th of February 2016 12:24:56 AM
Old 02-19-2016
Perhaps something like:
Code:
awk -F, '
{	printf("%*s %s %s\n", length($1),
	    (last == $1) ? "" : last = $1, $2, $3)
}' file

As always, if you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK line by line instead of field by field?

I've been using a lot of awk lately for csv files. But I've been using awk for csv files that contain 32 fields per line. For the first time, I've been given a csv file that contains one field per line (13 fields in each csv file). I need to check that a specific field, or line contains a... (2 Replies)
Discussion started by: yongho
2 Replies

2. Shell Programming and Scripting

Remove duplicate lines (the first matching line by field criteria)

Hello to all, I have this file 2002 1 23 0 0 2435.60 131.70 5.60 20.99 0.89 0.00 285.80 2303.90 2002 1 23 15 0 2436.60 132.90 6.45 21.19 1.03 0.00 285.80 2303.70 2002 1 23 ... (6 Replies)
Discussion started by: joggdial3000
6 Replies

3. Shell Programming and Scripting

Trying to use sed to remove the value of one field from another field

I'm trying to use sed to remove the value of one field from another field. For example: cat inputfile 123|ABC|Generic_Textjoe@yahoo.com|joe@yahoo.com|DEF 456|GHI|Other_recordjohn@msn.com|john@msn.com|JKL 789|MNO|No_Email_On_This_One|smith@gmail.com|PQR I would like to remove the email... (2 Replies)
Discussion started by: bribri87
2 Replies

4. Shell Programming and Scripting

Compare Field in Current Line with Field in Previous

Hi Guys I have the following file Essentially, I am trying to find the right awk/sed syntax in order to produce the following 3 distinct files from the file above: Basically, I want to print the lines of the file as long as the second field of the current line is equal to the... (9 Replies)
Discussion started by: moutaye
9 Replies

5. Shell Programming and Scripting

sed to replace a field from a line with another field

i have something like this, cat filename.txt hui this si s"dfgdfg" omeone ipaddress="10.19.123.104" wel hope this works i want to replace only 10.19.123.104 with different ip say 10.19.123.103 i tried this sed -i "s/'ipaddress'/'ipaddress=10.19.123.103'/g" filename.txt ... (1 Reply)
Discussion started by: vivek d r
1 Replies

6. Shell Programming and Scripting

How to remove line feeder in one field.?

Hi Gurus, I have another question (sorry, too many questions). I need remove the line feeder in one field. the file is comma delimted with double quote option which means the comma within double quote is not delimiter. "abc", "cde", "abc, cde", "def" "dgh", "ded", "cdd, ", "ghd" ... (1 Reply)
Discussion started by: ken6503
1 Replies

7. UNIX for Dummies Questions & Answers

Using awk to remove duplicate line if field is empty

Hi all, I've got a file that has 12 fields. I've merged 2 files and there will be some duplicates in the following: FILE: 1. ABC, 12345, TEST1, BILLING, GV, 20/10/2012, C, 8, 100, AA, TT, 100 2. ABC, 12345, TEST1, BILLING, GV, 20/10/2012, C, 8, 100, AA, TT, (EMPTY) 3. CDC, 54321, TEST3,... (4 Replies)
Discussion started by: tugar
4 Replies

8. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

9. Shell Programming and Scripting

awk to remove line if field has symbols in it

Trying to use awk to remove a line only if $1 contains either ; or :. Thje awk below runs but no lines are removed. Thank you :). awk awk '$1 !~ /;/ || $1 !~ /:/ { print }' file file AARS2;TMEM151B 1 AASS 2 ABAT 3 ABCA1 3 ABCA10 1 ABCA12 2 ABCA13 1 ABCA13:AX746840 2 ABCA2 5 (5 Replies)
Discussion started by: cmccabe
5 Replies
LOCATE(1)						    BSD General Commands Manual 						 LOCATE(1)

NAME
locate -- find filenames quickly SYNOPSIS
locate [-0Scims] [-l limit] [-d database] pattern ... DESCRIPTION
The locate program searches a database for all pathnames which match the specified pattern. The database is recomputed periodically (usually weekly or daily), and contains the pathnames of all files which are publicly accessible. Shell globbing and quoting characters (``*'', ``?'', ``'', ``['' and ``]'') may be used in pattern, although they will have to be escaped from the shell. Preceding any character with a backslash (``'') eliminates any special meaning which it may have. The matching differs in that no characters must be matched explicitly, including slashes (``/''). As a special case, a pattern containing no globbing characters (``foo'') is matched as though it were ``*foo*''. Historically, locate only stored characters between 32 and 127. The current implementation store any character except newline (' ') and NUL (''). The 8-bit character support does not waste extra space for plain ASCII file names. Characters less than 32 or greater than 127 are stored in 2 bytes. The following options are available: -0 Print pathnames separated by an ASCII NUL character (character code 0) instead of default NL (newline, character code 10). -S Print some statistics about the database and exit. -c Suppress normal output; instead print a count of matching file names. -d database Search in database instead of the default file name database. Multiple -d options are allowed. Each additional -d option adds the specified database to the list of databases to be searched. The option database may be a colon-separated list of databases. A single colon is a reference to the default database. $ locate -d $HOME/lib/mydb: foo will first search string ``foo'' in $HOME/lib/mydb and then in /var/db/locate.database. $ locate -d $HOME/lib/mydb::/cdrom/locate.database foo will first search string ``foo'' in $HOME/lib/mydb and then in /var/db/locate.database and then in /cdrom/locate.database. $ locate -d db1 -d db2 -d db3 pattern is the same as $ locate -d db1:db2:db3 pattern or $ locate -d db1:db2 -d db3 pattern If - is given as the database name, standard input will be read instead. For example, you can compress your database and use: $ zcat database.gz | locate -d - pattern This might be useful on machines with a fast CPU and little RAM and slow I/O. Note: you can only use one pattern for stdin. -i Ignore case distinctions in both the pattern and the database. -l number Limit output to number of file names and exit. -m Use mmap(2) instead of the stdio(3) library. This is the default behavior and is faster in most cases. -s Use the stdio(3) library instead of mmap(2). ENVIRONMENT
LOCATE_PATH path to the locate database if set and not empty, ignored if the -d option was specified. FILES
/var/db/locate.database locate database /usr/libexec/locate.updatedb Script to update the locate database /System/Library/LaunchDaemons/com.apple.locate.plist Job that starts the database rebuild SEE ALSO
find(1), whereis(1), which(1), fnmatch(3), locate.updatedb(8) Woods, James A., "Finding Files Fast", ;login, 8:1, pp. 8-10, 1983. HISTORY
The locate command first appeared in 4.4BSD. Many new features were added in FreeBSD 2.2. BUGS
The locate program may fail to list some files that are present, or may list files that have been removed from the system. This is because locate only reports files that are present in the database, which is typically only regenerated once a week by the /System/Library/LaunchDaemons/com.apple.locate.plist job. Use find(1) to locate files that are of a more transitory nature. The locate database is typically built by user ``nobody'' and the locate.updatedb(8) utility skips directories which are not readable for user ``nobody'', group ``nobody'', or world. For example, if your HOME directory is not world-readable, none of your files are in the data- base. The locate database is not byte order independent. It is not possible to share the databases between machines with different byte order. The current locate implementation understands databases in host byte order or network byte order if both architectures use the same integer size. So on a FreeBSD/i386 machine (little endian), you can read a locate database which was built on SunOS/sparc machine (big endian, net). The locate utility does not recognize multibyte characters. BSD
August 17, 2006 BSD
All times are GMT -4. The time now is 10:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy