Tag Info

Hot answers tagged

4

echo $above_string | grep -oP "^([^?]*\?){2}\K[^?]*" Change 2 to the n - 1 value in order to obtain the nth string. This assumes that you want the nth string in that line. You have n - 1 strings with no ? ending with a literal '?' (\? since it's a special character in perl regex). Then with \K you state you are not interested in the previous contents, ...


3

easier than fdisk for your purpose is lsblk: $ lsblk --nodeps NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 223.6G 0 disk sdb 8:16 0 298.1G 0 disk sr0 11:0 1 12M 0 rom or if you just want the drives: $ lsblk --nodeps -n -o name sda sdb sr0


2

This is standard procedure for awk awk ' { k=$2 for (i=3;i<=NF;i++) k=k " " $i if (! a[$1]) a[$1]=k else a[$1]=a[$1] "<br>" k } END{ for (i in a) print i "\t" a[i] }' long.text.file If file is sorted by first word in line the script can be more simple awk ' { if($1==k) printf("%s","<br>") else { ...


2

There are several programs for making socket connections from the command line (or via a shell script). The most common is probably netcat, of which there are at least three implementations: Original one ©1995-1996 Avian Research (Hobbit's netcat). No good upstream link I'm aware of, so here it is in the Debian package tracker: ...


1

Try this: blkid | awk -F":" '{print $1}'


1

With sed: sed '$!N;/^\([^\t]*\t\)\(.*\)\(\n\)\1/!P;s//\3\1\2<br>/;D' <<\IN word1 some text word1 some other text word1 some other other text word2 more text word3 even more word3 and still more IN (note: with many seds the above \t escape is invalid and a literal <tab> character should be used in its place) And if you have GNU sed ...


1

This is indeed standard for awk. Here is a terse solution that doesn't change operational data: awk 'BEGIN { FS="\t" } $1!=key { if (key!="") print out ; key=$1 ; out=$0 ; next } { out=out"<br>"$2 } END { print out }'


1

In python: import sys def join(file_name, join_text): prefix = None current_line = '' for line in open(file_name): if line and line[-1] == '\n': line = line[:-1] try: first_word, rest = line.split('\t', 1) except: first_word = None # empty line or one without tab rest = ...



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