# --------------------------------------------------------- # --- : How can I remove the first line of a text file using bash/sed script? # sed '1d' # --------------------------------------------------------- # --- : delete the first line from the file and save it with updated contain. sed -i '1d' filename # --------------------------------------------------------- # --- : # # line1 # line2 # line3 # line4 # line5 # line6 sed 'N; s/\n//' infile # line1line2 # line3line4 # line5line6 # --- :Not nice but works for 3 lines in one: sed 'N; s/\n//; N; s/\n//' infile # line1line2line3 # line3line4line6 # # sed ':a;N;$!ba;s/\n/ /g' # cat /etc/passwd | awk -F':' '!/user/ {print $1}' | sed ':a;N;$!ba;s/\n/ /g' root daemon bin sys sync games man lp mail news uucp proxy www-data backup list irc gnats nobody systemd-network systemd-resolve syslog messagebus _apt lxd uuidd dnsmasq landscape pollinate sshd docker glances smmta smmsp
Add character to the beginning of each line using sed
# --------------------------------------------------------- # --- Add character to the beginning of each line using sed # sed 's/^/#/' file.txt sed 's/^/ /' file.txt sed 's/^/ /' file.txt > new-file.txt
Howto: Linux command line utilities for removing blank lines from text files
# Task: Remove blank lines using sed sed '/^$/d' input.txt > output.txt # Task: Remove blank lines whit space/tabs using sed: sed '/^\s*$/d' # Task: Remove blank lines using grep grep -v '^$' input.txt > output.txt
How to remove XML tags from Unix command line?
sed -e 's/<[^>]*>//g' file.xml # echo "$WERK_CONNECTION" | awk 'NR==2' RS='<|>'
<!-- connection.xml --> <server-name> <serverName>xxxx<serverName/> <databaseName>xxxx<databaseName/> <portNumber>1234<portNumber/> <user>xxxx<user/> <password>xxxx<password/> <DatabaseEnv>test<test/> </server-name>
#!/bin/bash SERVER_ID='server-name' # DB_XML_FILE='connection.xml' # WERK_CONNECTION=$(fgrep "<$SERVER_ID>" "$DB_XML_FILE" -A17) # SERVER_NAME=$(echo "$WERK_CONNECTION" | awk 'NR==2'| sed 's/\t//g;s/<[^>]*>//g') DATABASE_NAME=$(echo "$WERK_CONNECTION" | awk 'NR==3'| sed 's/\t//g;s/<[^>]*>//g') DATABASE_PORT_NUMBER=$(echo "$WERK_CONNECTION" | awk 'NR==4'| sed 's/\t//g;s/<[^>]*>//g') DATABASE_USER=$(echo "$WERK_CONNECTION" | awk 'NR==5'| sed 's/\t//g;s/<[^>]*>//g') DATABASE_PASS_WORD=$(echo "$WERK_CONNECTION" | awk 'NR==6'| sed 's/\t//g;s/<[^>]*>//g') DATABASE_ENV=$(echo "$WERK_CONNECTION" | awk 'NR==7'| sed 's/\t//g;s/<[^>]*>//g') #
How to strip multipe spaces to one using sed?
# --------------------------------------------------------- # --- : How to strip multipe spaces to one using sed? # sed -e's/ */ /g' tr -s \ # ---------------------------------------------------------
# --------------------------------------------------------- # --- : Insert a line before or after a pattern # # Inserting before the pattern: awk '/XYZpattern/{print "#-------"}1' file sed 's/.*XYZpattern.*/#-------\n&/' file # Inserting after the Pattern: awk '/XYZpattern/{print;print "#-------";next}1' file sed 's/.*XYZpattern.*/&\n#-------/' file # ---------------------------------------------------------