In: Computer Science
unix
Hi there, if you need any further guidance and having any issues while executing commands do comment, I'll be happy to help you.
I have solved first 5 problems as per time limit, you post again the rest questions.
if you like my solution do cleave a positive feedback and a thumbs up.
commands
sed 's/.//2' sample
sample is your file name
2.Delete the last word from every line in a file.
sed s/'\w*$'// old.txt > new.txt
\w*
matches the last word inside of the file and
$
anchors the search to the end of the line.
The reason that old.txt is coming out as new.txt is likely
because your regular expression ^*\n
is not matching
any lines in old.txt.
3. Swap the first and second letter of every line in a file.
sed -e "s/\([^ ]*\) *\([^ ]*\)/\2 \1 /g" file
4. Swap the first and last characters of every line in a file.
sed -E 's/(.)(.+)(.)/\3\2\1/' input.txt
5.For each line that begins with a single space, replace the space with a tab. Lines that begin with 2 or more spaces should not be effected.
sed 's/^ */\t/' < file.in > file.out
or,
sed 's/ /'$'\t''/' filename