The tag has no wiki summary.

learn more… | top users | synonyms

11
votes
8answers
907 views

How do I get the character count of words in a particular column?

I have a CSV file like this: abd,123,egypt,78 cde,456,england,45 How can I get the character count of only the 3rd column words? I can't figure out how to get wc to do this.
9
votes
2answers
6k views

Is there a simple command for outputting tab-delimited columns in bash?

E.g. I have a file (produced with echo -e "var1\tvar2\t\var3\tvar4" > foo) that are output (in bash): $ cat foo case elems meshing nlsys uniform 2350 0.076662 2.78 non-conformal ...
8
votes
7answers
374 views

Swapping an unlimited number of columns

I have a file with columns. See below for an example: a b c ... z 1 2 3 ... 26 I'd like to swap all columns where the 1st becomes the last, the second becomes the one before last...etc.. z y x ...
6
votes
2answers
1k views

How can I use column to delimit on tabs and not spaces?

I'd like to use Unix column to format some text. I have fields delimited by tabs, but within each field there are also spaces. column delimits on white space (tabs and spaces). How can I make column ...
6
votes
3answers
82 views

Print a multiline variable in a column

I have a script that collects values from a cluster. The values, in some cases, have multiple lines. I have a printf format that specifies how the data should be positioned however, it doesn't take ...
5
votes
3answers
3k views

How can sed output be formatted like printf's formatted printing?

Can sed replace text with a string formatted like printf's formatted printing? The following sed command replaces a line starting with the current value of "$domain" with several values specified in ...
5
votes
3answers
6k views

Search for values in 2 columns from CSV

I have a csv files with say 20 odd columns. I need to get the 14th and 15th column values where value in 14th column is say "VALUE1" and value in 15th column is "VALUE2". My condition gets satisfied ...
5
votes
2answers
78 views

Sort one column only, keeping remaining columns untouched

How to (numerically) sort a specific column in a text file, without affecting other columns (irrespective of whether they are sorted or unsorted)? On other threads I found -s argument, but it does ...
4
votes
5answers
647 views

A better paste command

I have the following two files ( I padded the lines with dots so every line in a file is the same width and made file1 all caps to make it more clear). contents of file1: ETIAM...... SED........ ...
4
votes
4answers
576 views

Joining two files with unique identifier

I have two files with approximately 12900 and 4400 entries respectively, that I want to join. The files contain location information for all landbased weather observing stations around the globe. The ...
4
votes
2answers
119 views

Replace common values in two files according to first column

How do I replace common values in two files according to first column? I have file 1 (1.txt): CH063_01084 CH063_01083 CH063_13925 CH063_14473 and file 2 (2.txt): CH063_01083 FGSG_16349 4 ...
4
votes
5answers
100 views

Reformat each two-line sequence into two columns

I would like to tab my printout: 1 2 3 4 5 6 7 8 to 1 2 5 6 3 4 7 8 How to adjust it using simple command line (awk or sed)??
4
votes
3answers
532 views

using awk to split a line on single spaces not multiples

I'm trying to split a line that I have no control over the format of. If parameter 7 and 8 are missing which is possible they will be replaced by a space so I would end up with, field1 field2 field3 ...
4
votes
4answers
4k views

Compare two files: lines present in one, not in the other, by one column comparison

I need to compare 2 files. Column 1 is the same in both files. Column 2 is what I want to compare: I want all lines in file 1 that are not in file 2 when comparing column 2. Column 3 is different in ...
4
votes
4answers
4k views

Transposing rows and columns

I have a file with the lines like below. title1:A1 title2:A2 title3:A3 title4:A4 title5:A5 title1:B1 title2:B2 title3:B3 title4:B4 title5:B5 title1:C1 title2:C2 title3:C3 title4:C4 title5:C5 ...
4
votes
2answers
139 views

Column mismatch and substituting

input.txt (tab-delimted) TTTTOTTT00000000008 RTTTT899 5.00E-28 TTTTOTTT00000000046 RTTTWRR 3.00E-31 TTTTOTTT00000000051 2.00E-11 TTTTOTTT00000000051 7.00E-12 TTTTOTTT00000000054 ...
4
votes
2answers
172 views

AWK - a question about columns

I have a question. I was trying to deal with it by myself, but it seems like I am too new in awk to make it work. Let's assume that we have a file (eg. database.txt) (values are tab-separated): ...
4
votes
2answers
598 views

How to adjust column width in Linux command output

When I used this command on Red Hat Linux /usr/sbin/ss -i I get the following output below: State Recv-Q Send-Q Local Address:Port ...
4
votes
1answer
746 views

Linux sort second last column

I would like know how to sort the second last column ? It has the word "days=" in front of the number. I'm able to get the column with awk '{print $(NF-1)}', but sorting is wrong. 457000 ...
4
votes
4answers
171 views

Wrap sentences into columns

I'm looking for a way to take sentences and wrap them. Using something like column is not what I want as in my scenario there will be multiple sentence columns in the 80 characters. Is there any ...
4
votes
3answers
197 views

Parsing columnized data

I have some columnized data which I would like to format a little further. It looks like this: $ getStats | grep ESTABLISHED | column -t all tcp 117.54.56.131:80 <- 10.42.100.211:63752 ...
3
votes
6answers
137 views

How to combine contents of two files having the same value in a column?

File1: 00:00 274 00:04 476 00:05 450 00:06 499 00:07 373 00:08 206 00:09 471 00:10 154 File2: 00:00 183 00:01 60 00:02 344 00:03 540 00:04 450 00:07 348 00:09 473 00:10 203 Desired output: ...
3
votes
5answers
743 views

How can I concatenate a single column of output into a list?

I'm using: ls /proc | grep -v "^[0-9].*" to get a list of all the files and directories in /proc that don't begin with numbers. The output is a single column list, i.e.: acpi asound buddyinfo bus ...
3
votes
3answers
163 views

Easily get a particular column from output without sed or awk

Is there a quicker way of getting a couple of column of values than futzing with sed and awk? For instance, if I have the output of ls -hal / and I want to just get the file and directory names and ...
3
votes
5answers
2k views

Add character to beginning and end of column

I have a file like this: 78@54@this@15@23 65@22@is@92@16 34@12@an@14@18 13@42@example@52@22 And I want to change it to this: "78"@54@"this"@15@23 "65"@22@"is"@92@16 "34"@12@"an"@14@18 ...
3
votes
5answers
743 views

How to align fstab entries easily

Editing /etc/fstab with my text editor makes all the spacing go out of alignment. I could go through the file and insert/delete spaces to line everything up, but I'm looking for a more automated ...
3
votes
2answers
137 views

get the Xth argument in each line

I would like to get the second argument in a line of output. For example: ps aux gives me an output that contains the cpu-usage %CPU in the third column. How can I filter the output so I have only ...
3
votes
3answers
48 views

Removal of lines with more than 'N' fields?

I am working on mac with sed, perl, awk, bash.. I have a large-ish (10GB) text file which has 13 fields (columns) of TAB delimited data. Unfortunately some of these lines have extraneous TABs , so I ...
3
votes
2answers
999 views

Cut command not extracting fields properly in aligned columns

I have a text file in which I must cut the fields 3,4,5 and 8: 219 432 4567 Harrison Joel M 4540 Accountant 09-12-1985 219 433 4587 Mitchell Barbara C 4541 Admin Asst ...
3
votes
3answers
150 views

Subsetting a file's contents based on value in a column

I have a text file as (for example): apple V$NFY_Q6_rc V=0.741 apple V$HOXA7_01_rc V=0.454 apple V$ALPHACP1_01_rc V=0.695 orange V$SP4_Q5 V=0.747 grapes V$SP1_Q2_01 V=0.677 grapes ...
3
votes
1answer
108 views

Sort only on the second column [duplicate]

I'm trying to sort a file where typically (not always) the lines are whatever:[A-Ba-b0-9_]: values where fields are separated with :. Some lines do not follow this pattern, I'm not interested in ...
3
votes
3answers
253 views

Join every other column with sed or awk

I have a large text file (666000 colums) in the format A B C D E F Desired output AB CD EF How can we do it in sed or awk. I have tried a couple of things but nothing seems to be working. Please ...
3
votes
2answers
50 views

Compare 2 tab delimited files and output differences with column header

I would like to compare 2 similar files on a common column. The files will have identical headers. file1.txt mem_id Date Time Building aa bb cc dd ee ff ...
3
votes
2answers
2k views

Top Command - How to reduce the displayed Columns

Can we get specific column in a top command, for eg I'm interested in only the memory utilization and CPU usage column. How do I reduce the displayed columns of the top command to only the above two ...
3
votes
3answers
155 views

How can I get the first column of a 300GB txt file?

let me first explain my problem in detail. It's actually pretty simple. I have a huge .txt file, 300GB to be more preciese, and I would like to put all the distinct strings from the first column, that ...
3
votes
4answers
2k views

How to reorder a large number of columns?

I'm looking for a pipeable one-liner to reorder a large number of columns (where manually entering the column numbers in e.g. an awk command such as awk '{print $3,$2,$1}' is not feasible). The order ...
3
votes
3answers
151 views

Append columns in a text file to after the final row

A smaller version of many data files I have looks like this: 0 0 0 0.05 9.6877884e-06 0.0024898597 0.1 4.2838688e-05 0.0049595502 0.15 0.00016929444 0.0074092494 0.2 0.00036426881 0.009839138 0.25 ...
3
votes
1answer
143 views

zsh and COLUMNS

I cannot understand the behavior of the $COLUMNS variable under zsh. Here's an example of the sort of behavior I'm referring to. The script $HOME/cols.sh is the following: echo "COLUMNS=$COLUMNS" ...
2
votes
3answers
171 views

how to create a data file with a column of date from day1 to dayN?

I was wondering if I could generate a hourly or daily time step date in a column starting from some year in the past to some day in the near past or today. to be more clear, I want to create one ...
2
votes
3answers
473 views

changing column separators in a file

I have a large file, that I need to process and after writing some scripts that don't seem to work properly, I have discovered that a small subset of the lines in the file are actually space separated ...
2
votes
3answers
5k views

print output to 3 separate columns

MYPATH=/var/www/html/error_logs/ TOTALFILE=$(ls $MYPATH* | wc -l) FILETIME=$(stat --format=%y $MYPATH* | head -5 | cut -d'.' -f1) FILE=$(ls -1tcr $MYPATH* | head -5 | rev | cut -d/ -f1 | rev) ...
2
votes
2answers
750 views

Bash: append columns to table

If you want to append a column (not a line) to a table, and the column has the same number of elements for sure, how can you do it? Given a set of files, which keeps changing each day, you want to ...
2
votes
3answers
385 views

How does this awk align the spacing?

Can someone please tell me what does this do? cat infile| awk ' { for(i=3;i<=NF;i++){ $2=$2" "$i } printf "%-4s %s\n", $1,$2 ; }' > outfile.txt infile contains: 1 John Smith 2 ...
2
votes
2answers
177 views

Create an ASCII art table from tabular data

Given perhaps comma- or tab-delimited input, I'd like to present a series of appropriately padded columns to stdout, so I can easily scan columnar information which would otherwise present rather ...
2
votes
2answers
107 views

“Fill columns before rows” option in unix column command

According to man column: -x Fill columns before filling rows. This option doesn't seem to do anything. Any idea how to use it?
2
votes
2answers
137 views

add fields from different files

I have two files A and B with the same number of lines. Each of them has multiple columns. I want to add field 6 in file A with field 3 in file B for each line. e.g.: file A: 2769 RUT10EKl3fY 0 ...
2
votes
2answers
40 views

Merging files by rows

Is it possible to copy the whole rows of File1 in a new File3 following the instruction given by File2 by using a simple bash script using sed or awk? File1: /*two or more columns*/ AC 456324 DC ...
2
votes
2answers
244 views

Merging multiple lines based on column 1

I have a file like below.. abc, 12345 def, text and nos ghi, something else jkl, words and numbers abc, 56345 def, text and nos ghi, something else jkl, words and numbers abc, 15475 def, ...
2
votes
5answers
1k views

Sum the values in a column except the header

I have a file as given below -------------------------------------------------------------- Name_Customer Item_Purchased Item_Amount Credit ...
2
votes
4answers
1k views

Extract lines from a text file with one column equal to the maximum

I have a text file (with header line) called file.txt. I am trying to extract the lines equal to the maximum value of a specific column (I do not know what the max value is): ID t1 q1 t2 q2 q3 1 f ...