Visit Our UNIX and Linux User Community

Search Results

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

. ./run.sh



It runs in a subshell.
15,602
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,136
Posted By Scrutinizer
sed 's|[^ ][^ ]*|&_label|2' infile
sed 's|[^ ][^ ]*|&_label|2' infile
2,012
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...
1,978
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
4,136
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
1,978
Posted By ctsgnb
echo "file1.txt file2.txt ... filen.txt" | sed...
echo "file1.txt file2.txt ... filen.txt" | sed 's/\([^ ][^ ]*\)/\$1\1/g'
43,392
Posted By bartus11
perl -ne 'print unless $a{$_}++' file
perl -ne 'print unless $a{$_}++' file
4,075
Posted By k_manimuthu
perl -i -pe 's/^\s+$//g' file
perl -i -pe 's/^\s+$//g' file
8,418
Posted By rdcwayx
echo "qwertmyuiop" |awk 'BEGIN{FS=OFS=""}{print...
echo "qwertmyuiop" |awk 'BEGIN{FS=OFS=""}{print $(NF/2+1)}'
60,696
Posted By rdcwayx
echo "Youcaneasilydothisbyhighlightingyourcode."...
echo "Youcaneasilydothisbyhighlightingyourcode." |awk 'BEGIN{FS=OFS=""}{for (i=1;i<=NF;i++) {if (i%3==0) $i=$i " "}}1'
14,433
Posted By Scrutinizer
It removes all non-slash characters and then...
It removes all non-slash characters and then calculates the line length
14,433
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
14,433
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...
8,418
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...
2,158
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.
14,778
Posted By danmero
Shorter one ;) awk -F: '$0=$1' file or cut...
Shorter one ;)
awk -F: '$0=$1' file
or
cut -d: -f1 file
60,696
Posted By konsolebox
Or you can just use &: sed 's/.\{3\}/&...
Or you can just use &:
sed 's/.\{3\}/& /g'
60,696
Posted By kevintse
echo "Youcaneasilydothisbyhighlightingyourcode."...
echo "Youcaneasilydothisbyhighlightingyourcode." | sed 's/\(.\{3\}\)/\1 /g'
3,212
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...
14,778
Posted By kevintse
awk -F: '{print $1}' infile
awk -F: '{print $1}' infile
3,212
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.
...
6,693
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...
14,778
Posted By Scott
sed "s/:.*//"
sed "s/:.*//"
3,212
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.
Showing results 1 to 25 of 37

 

Featured Tech Videos

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