6

The simplest approach would be to remove all numbers after the first . on every line: $ sed 's/\.[0-9]*/\./' file target_id length eff_length est_counts tpm ENST00000583162. 1066 967 1.69899 1.18376 ENST00000583355. 891 792 13.8057 11.7445 ENST00000582528. 5342 5243 21.3223 2.74003 ...


3

An awk solution is awk '{if(NF){gsub(/^ |,$/,""); printf c $0; c=","}else{printf "\n"; c=""}};END{printf "\n"}' expanded with comments: { if(NF) { # if the line isn't empty gsub(/^ |,$/,""); # remove the first space and last comma printf c $0; # print the line (without a newline) c="," # set c to add a comma for the next field ...


3

Here Strings seem to produce a newline at the end: You can try and see the difference: cat <<<"test" cat <(printf '%s' "test") So, you should use < <(printf '%s' "$line") instead of <<<"$(printf '%s' "$line")".


3

You can use read to split the lines based on whitespace (which it looks like your file uses). Something like this: while read set year; do DoStuffWith "$set" "$year" done <test.txt Other notes: Note that I used lowercase variable names in the above example. There are a bunch of all-caps names with special meanings, and the safest way to avoid ...


2

To replace each alphabetic character by the letter N: tr '[:alpha:]' N < file.txt > file2.txt


2

With GNU awk, you can do gawk -v start=5 -v end=8 '{ mid = substr($0, start, end-start+1) print substr($0, 1, start-1) gensub(/./, "N", "g", mid) substr($0, end+1) }' file Or with perl perl -spe 'substr($_, $start-1, $end-$start+1) =~ s/./N/g' -- -start=5 -end=8 file With both solutions, we pass the start and end values to the program with ...


2

If you have GNU awk (gawk) you could set FIELDWIDTHS to split the line into fields based on character positions. This is particularly convenient for your case in gawk version >= 4.2, which supports a "wildcard" trailing fieldwidth. You can then replace characters in the second field using gsub: echo ABCDABCDABCD | ./gawk -v i=5 -v n=4 ' BEGIN {FIELDWIDTHS ...


2

I would write: while IFS= read -r line; do for ((i=0; i<${#line}; i++)); do char=${line:i:1} ((count++)) ((low <= count && count <= high)) && char=$new_char printf '%s' "$char" done echo done <"$input"


2

try awk '{$1=$1*10 ; print }' this will change first parameter, and print whole line. to keep formating to 3 digit, use awk '{$1=sprintf("%.3f",$1*10);print;}'


2

Try this, awk -F '@' '{print $0"|"$NF}' file TEST|1234|john.doe@gmail.com|gmail.com TEST|4533|jeffp12@yahoo.com|yahoo.com TEST|9030|indoep13@gmx.com|gmx.com TEST|0903|ramdpe23@gmail.com|gmail.com


1

awk 'NR==1{print "z(A) " $0 " OW HW1 HW2"; next}1' or awk 'NR==1{printf "z(A) %s OW HW1 HW2\n", $0; next}1' or awk 'NR==1{$0="z(A) " $0 " OW HW1 HW2"}1'


1

sed -e '1s/^/z(A) /' -e '1s/$/ OW HW1 HW2/' < input > output 1 is for the first line, s is for substitute, ^ is beginning-of-line, $ is end-of-line.


1

In ksh, you can also use arrays: while IFS='#' read -A arr; do echo "${#arr[@]} items, second item: ${arr[1]}" done < file read -A works in Zsh too, but the array indexes are one-based. Bash's read -a works similarly to the ksh one.


1

You can use parameter expansion if that's what you mean. But it's not very readable: while read a; do # comments are for the first line A#B#C f1f2=${a%#*} # remove suffix #C -> A#B f1=${f1f2%#*} # remove suffix #B -> A f2=${f1f2#*#} # remove prefix A# -> B f3=${a##*#} # remove longest prefix: A#B# -> C echo "$f1,$f2,$f3" # do ...


1

If what you mean by "generic" is that the number of columns can change and you always want to write all of them to a file whose name is defined by the 1st 3 fields, then you can try this: awk -F\| '{ data=$4 for(i=5;i<=NF;i++){ data = data"|"$(i) } print data > "sample_"$1"_"$2"_"$3".CSV"}...


1

You can get the best results from awk: awk '{ print > "index i"$2 }' < input You can also do it purely in the shell: while read a b c do printf '%s\n' "$a $b $c" >> "index i$b" done < input The awk solution has these advantages: It will overwrite existing files.  The shell script will append to existing files.  (I suppose that ...


1

sed -E 's,^([0-9]+)/([0-9]+),\2/\1,' Explanation sed -E: use sed with extended regular expressions so we don't have to escape the (), etc. s/foo/bar/: this is the general sed syntax to search for foo and replace it with bar. Here, I've used , instead of /, because there are /s in the expression, and this will simplify it (again avoiding confusing escaping. ...


1

$ tr -d '\n' <file | perl -pe 'substr($_, 9, 4, "P"x4)' | fold -w 5 NNNNN NNNNP PPPNN NNNNN This first removes all newlines from the data in the input file, then uses substr() in Perl to replace the text at offset 9 of length 4 with upper-case P. The fold utility is then used to fold the lines at five characters. There is no newline at the end of the ...


1

Using sed To replace characters 5 through 8 with N: $ sed -E 's/(.{4}).{4}/\1NNNN/' test ABCDNNNNABCD How it works: (.{4}) captures the first four characters in group 1. .{4} matches the next four characters. \1NNNN replaces the above with group 1 and four N. Using GNU awk $ gawk -F "" '{for (i=5; i<=8; i++) $i="N"} 1' OFS="" test ABCDNNNNABCD ...


1

You could use perl, which is a pretty powerful text manipulator: perl -pi -e 's/(^ver="\d+)\.(\d+)\.(\d+)"/"$1.$2." . sprintf("%04d", $3+1) . "\""/e' input This invokes perl with three options: -p -- auto-print each line of input -i -- edit the file in-place -e -- use the next argument as the code to execute The code says to do a search & replacement ...


1

Assuming that the patch level is always going to be a string of four digits: $ ver=1.2.0001 $ printf '%s\n' "$ver" | awk -F '.' '{ printf("%s.%s.%04d\n", $1, $2, $3 + 1) }' 1.2.0002 This uses awk and treats the version as three fields delimited by dots. It prints the first two fields as they are, but adds 1 to the third field and formats the result using %...


1

The easiest way to achieve it is sed: sed 's/[A-Z]/N/g' file.txt (add -i if you want in-place file changes). PS. Note, that the expression above is case sensitive. If you want case-insensitive replacement use something like this: sed 's/[A-Z]/N/Ig' file.txt


1

Assuming you'd like to append the contents of the file template to the file data only if no line from template already exists in data. The command for testing whether a line in template is found in data is grep -xF -f template data (This is a reasonable thing to do only if template contains less than a few thousands of lines) This uses the following ...


Only top voted, non community-wiki answers of a minimum length are eligible