Search Results

Search: Posts Made By: cola
1,393
Posted By verdepollo
source your script: . ./run.sh It...
source your script:

. ./run.sh



It runs in a subshell.
21,116
Posted By rbatte1
Try "man id" for variants
Dear cola,id -unwill give you the text name of the first user listed in /etc/passwd with your uid number.
id -gn will give you the text name of the first group in /etc/group that matches your...
4,577
Posted By Scrutinizer
sed 's|[^ ][^ ]*|&_label|2' infile
sed 's|[^ ][^ ]*|&_label|2' infile
2,194
Posted By Scrutinizer
I think alister's is the most elegant, though it...
I think alister's is the most elegant, though it leaves str open to wildcard expansion by the shell if you are using any.
Using sed:
sed 's|[^ ][^ ]*|$1/&|g'
similar to ctsgnb's suggestion
2,464
Posted By Scrutinizer
It is because the * gets interpreted and expanded...
It is because the * gets interpreted and expanded by the shell to the content of the current directory. Just go into a directory and issue:

var=*
echo $var
If you put quotes around $var, you...
4,577
Posted By Aia
sed "s/ *[^ ]*/&_label/" file doesn't have a...
sed "s/ *[^ ]*/&_label/" file doesn't have a global flag, therefore it matches only the first instance in each line.
sed "s/ *[^ ]*/&_label/g" file
Will just do what you originally thought
2,194
Posted By ctsgnb
echo "file1.txt file2.txt ... filen.txt" | sed...
echo "file1.txt file2.txt ... filen.txt" | sed 's/\([^ ][^ ]*\)/\$1\1/g'
51,618
Posted By bartus11
perl -ne 'print unless $a{$_}++' file
perl -ne 'print unless $a{$_}++' file
4,542
Posted By k_manimuthu
perl -i -pe 's/^\s+$//g' file
perl -i -pe 's/^\s+$//g' file
10,102
Posted By rdcwayx
echo "qwertmyuiop" |awk 'BEGIN{FS=OFS=""}{print...
echo "qwertmyuiop" |awk 'BEGIN{FS=OFS=""}{print $(NF/2+1)}'
69,307
Posted By rdcwayx
echo "Youcaneasilydothisbyhighlightingyourcode."...
echo "Youcaneasilydothisbyhighlightingyourcode." |awk 'BEGIN{FS=OFS=""}{for (i=1;i<=NF;i++) {if (i%3==0) $i=$i " "}}1'
16,678
Posted By Scrutinizer
It removes all non-slash characters and then...
It removes all non-slash characters and then calculates the line length
16,678
Posted By bartus11
Match operator (m//) returns all the matched...
Match operator (m//) returns all the matched strings as array. So @n contains all the "/"s matched in current line. $#n is index of array's last element, and because Perl starts indexing from 0, we...
16,678
Posted By Scrutinizer
Using sed you still need to count, e.g.: $ echo...
Using sed you still need to count, e.g.:
$ echo ghw//yw/hw///??u | sed s#[^/]##g | wc -L
6
10,102
Posted By Scrutinizer
:a is a label ( label "a" ) ta means jump to...
:a is a label ( label "a" )

ta means jump to label a is the previous command was successfull (if the s command managed to do a replacement)

So this creates a loop where after each iteration the...
69,307
Posted By konsolebox
Or you can just use &: sed 's/.\{3\}/&...
Or you can just use &:
sed 's/.\{3\}/& /g'
17,193
Posted By danmero
Shorter one ;) awk -F: '$0=$1' file or cut...
Shorter one ;)
awk -F: '$0=$1' file
or
cut -d: -f1 file
69,307
Posted By kevintse
echo "Youcaneasilydothisbyhighlightingyourcode."...
echo "Youcaneasilydothisbyhighlightingyourcode." | sed 's/\(.\{3\}\)/\1 /g'
4,575
Posted By Scott
[2addr]s/regular expression/replacement/flags ...
[2addr]s/regular expression/replacement/flags
Substitute the replacement string for the first instance of the regular expression in the pattern space.


If you leave out the .* then...
4,575
Posted By kevintse
If you remove the ".*" part from the regex, that...
If you remove the ".*" part from the regex, that means you want to match a line that has only 16 characters, this simply does not match anything, so the original string is output.
...
17,193
Posted By kevintse
awk -F: '{print $1}' infile
awk -F: '{print $1}' infile
7,293
Posted By kevintse
There are punctuations in your string, so: awk...
There are punctuations in your string, so:
awk -F"[ ,.]" '{for(i=1;i<=NF;++i) if($i!="")a[$i]} END {for(s in a) print s}' infile
If you insist on using FS, try this, it has the same output as the...
4,575
Posted By Scott
Aptly: $ sed "s/\(.\{16\}\).*/\1/" file1 ...
Aptly:


$ sed "s/\(.\{16\}\).*/\1/" file1
You can easily


I take 0 to 15 to mean 16 characters.
17,193
Posted By Scott
sed "s/:.*//"
sed "s/:.*//"
2,376
Posted By ASGR
sub-string extraction using bash
Assuming that you have the
file in an array already, then;
${ARRAY[@]:45:5}
will extract the arrays starting at 45
with a length of 5.
Showing results 1 to 25 of 37

 
All times are GMT -4. The time now is 06:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy