New answers tagged

0

The output of ls should never be parsed. Parsing ls is hard, column widths vary, number of columns can change mid-output, ... Use the stat command (man stat). stat will let you output the data you want, in the format you want. For example, stat --format="%s %n" * .*


0

Using Raku (formerly known as Perl_6) ls -hal / | raku -ne '.words[4,8].say;' OR ls -hal / | raku -ne '.words[4,8].put unless .words.elems < 8;' The OP seems to be searching for a language that helps with tabular data. For whatever reason, sed and awk don't fit the bill (which is fine, BTW). If you want a language that's built from the ground up to ...


1

If you just want to display these two attributes (size and name), you can also use the stat tool (which is designed for just that - querying file attributes): stat -c "%s %n" .* * will display the size and name of all files (including "hidden" files) in the current directory. Notice: You chose ls as one application example for the use ...


1

I'm amazed no one has written this already, but if your only objection to cut is that it won't handle repeated spaces as a single delimiter, how about you just squeeze the repeated spaces? That's one of the uses of tr. ls -l | tr -s ' ' | cut -d ' ' -f5,9 Given the ls -l output shown in your question, the result would be: 1.2K . 1.2K .. 15K .DS_Store 272B ....


0

You can do it find command ls -hal| awk 'NR>1{print $(NF-4),$NF}' Second option find . -maxdepth 1 -type f -printf "%s %p\n"


2

This is an old question, but at the risk of rocking the boat, I have to say I agree with @iconoclast: there really ought to be a good, simple way of extracting selected columns in Unix. Now, yes, awk can easily do this, it's true. But I think it's also true that it's "overkill" for a simple, common task. And even if the overkill factor isn't a ...


1

Since this is a simple substitution on individual lines I'd just use sed: $ sed 's/_KI[^_,]*_[^_,]*//g' file chr1,153401,rs867658023,chr1_153401 chr1,154751,rs1030747857,chr1_154751 chr1,156703,rs900345029,chr1_156703 chr1,156856,rs576837150,chr1_156856 but you can do the same with awk if you prefer: $ awk '{gsub(/_KI[^_,]*_[^_,]*/,"")} 1' file ...


-1

Considering the filename as a.txt and the separator is \t we can use the following command: cat a.txt | awk -F"\t" '{print $1 "\n" $2}' > b.txt Now b.txt will contain the expected output


0

@icarus awk is effectively just replacing with \n and you can achieve the same objective with other tools such as cat file | tr ' ' '\n' # Naughty me! See UUOC below. or sed "s/ /\n/g" file These will reduce a space separated row of 2 or more elements to a single "column" or perhaps more correctly, place each element on it's own ...


1

Guessing that the question means that the desired output is RSID1 RSID2 rs7475652 rs7475652 rs7475652 rs7918643 rs7475652 rs3125034 rs7475652 rs3750730 rs7475652 rs883728 rs7475652 rs4881500 rs7475652 rs3853288 rs7475652 rs4881504 rs7475652 rs2242271 rs7475652 rs7099607 rs7475652 rs10904597 rs7475652 rs3207775 then awk '{print $1 "\n" $2}' will ...


Top 50 recent answers are included