[Solved] how do I basic script with linux? [closed]

#!/bin/bash is called the shebang (you missed the leading #). It tells which program will execute your script. clear is for clearing screen. echo outputs following argument to the standard output (your terminal by default). But you must not surround your string with parenthesis as it’s used for grouping command in a sub-shell. If you … Read more

[Solved] Removing Leading Zeros within awk file [duplicate]

Try this: sub(/^0+/, “”, $2)? $ awk ‘BEGIN{b=”000000000000787301″; sub(/^0+/, “”, b); print b;}’ 787301 or typecast it by adding zero: $ awk ‘BEGIN{b=”000000000000787301″; print b+0;}’ 787301 update A working example based on comments: $ echo ‘E2EDP19001 02002000000000000797578’ | awk ‘{$2 = substr($2,6); sub(/^0+/, “”, $2); print $2;}’ 797578 or, preserve $2: $ echo ‘E2EDP19001 02002000000000000797578’ … Read more

[Solved] How to create list of jpg urls from file?

Have a look on the option “-o” (–only-matching) of grep command. By default grep keep lines that match the given pattern. With the option ‘-o’, grep will keep only the part of the line that match your url pattern 0 solved How to create list of jpg urls from file?

[Solved] Find rows with the same value in a column in two files

Let’s say your dataset is big in both dimensions – rows and columns. Then you want to use join. To use join, you have to sort your data first. Something along those lines: <File1.txt sort -k2,2 > File1-sorted.txt <File2.txt sort -k3,3 -S1G > File2-sorted.txt join -1 2 -2 3 File1-sorted.txt File2-sorted.txt > matches.txt The sort … Read more

[Solved] How to move everything following a dash to a new column?

You could try this for a input-file called input: csplit -f tempfile input ‘/-/+1’ ‘{*}’; paste tempfile* With csplit we generate one file for each “column” in the desired output (tempfile01, tempfile02, …). Next, we merge these temporary files. With the given sample input, the output of the above command is: jim sally bill jerry … Read more

[Solved] Store rsync error in variable

The line you have put here will just store that command as a string and not run it. rsync_error=”rsync -arzt –ignore-existing –delete –max-delete=1 -e ‘ssh’ [email protected]:$rsync_from_location $rsync_to_location” To capture its output you would need to put it in a $( ) like so. rsync_error=$(rsync -arzt –ignore-existing –delete –max-delete=1 -e ‘ssh’ [email protected]:$rsync_from_location $rsync_to_location) This will capture … Read more

[Solved] Link separated words [closed]

Assuming you have How are you.pdf in a variable you can use parameter expansions: % a=”How are you.pdf” % echo “${a// /.}” How.are.you.pdf The above is a bash expansion and doesn’t work in a POSIX shell. In that case sed or simulare would be needed. To rename all files in the current directory: for a … Read more

[Solved] how do I convert the first letter of every word in a list from upper case to lower case? [duplicate]

If you have gnu sed then use: sed -i ‘s/[A-Z]/\L&/’ file [A-Z] will match first upper case letter & is back-reference of matched string by pattern (in this case single upper case letter) \L converts given back-reference to lowercase solved how do I convert the first letter of every word in a list from upper … Read more

[Solved] Append text to each of multiple lines in file

Use something simple like sed: sed -r ‘s/^([0-9]*)$/update “table1” set event_type = \’NEW\’ where id=\1/’ file | write back using \1 as placeholder catch digits in the file Previous answer I used an approach based on bash loops, whereas it is a bit overkilling. See a related question: Why is using a shell loop to … Read more