Question

In: Computer Science

unix Delete the second character from every line in a file Delete the last word from...

unix

  1. Delete the second character from every line in a file
  2. Delete the last word from every line in a file.
  3. Swap the first and second letter of every line in a file.
  4. Swap the first and last characters of every line in a file.
  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.
  6. Finds dates in the form mm/dd/yy and replaces them with the form mm/dd/20yy. In other words puts 20 in front of a 2 digit year. 4 digit years should not be changed.
  7. Move lines 3 through 5 after line 8 (so the output lines would be in order 1,2,6,7,8,3,4,5,9,10,....)
  8. Given a line with a UNIX path specified, print the base file name only. So for example, "/home/users/james" would print "james"
  9. Given a line with a UNIX path specified, print the directory part only. So for example, "/home/users/james" would print "home/users"

Solutions

Expert Solution

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

  1. Delete the second character from every line in a file

  

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

Related Solutions

unix Delete the second character from every line in a file Delete the last word from...
unix Delete the second character from every line in a file Delete the last word from every line in a file. Swap the first and second letter of every line in a file. Swap the first and last characters of every line in a file.
Whats the code to open a text file and every line in that text file that...
Whats the code to open a text file and every line in that text file that starts with # then it should delete that line In python using .strip
Create a c file to read from an existing file one character at a time and...
Create a c file to read from an existing file one character at a time and print that character to the console Create a c file to read a character from the standard input and write it to a file. please help me
Assignment in C programming class: read the text file line by line, and place each word,...
Assignment in C programming class: read the text file line by line, and place each word, in order, in an array of char strings. As you copy each word into the array, you will keep a running count of the number of words in the text file and convert the letters of each word to lower case. Assume tgat you will use no more than 1000 words in the text, and no more than the first 10 characters in a...
You are asked to delete the last occurrence of an item from a linked list. So,...
You are asked to delete the last occurrence of an item from a linked list. So, for instance: Input: 2 -> 3 -> 2 -> 4 Delete last occurrence of 2, result: 2 -> 3 -> 4 Implement the following method to do the deletion. You may NOT use or implement helper methods - all your code must be implemented inside the given method. You may NOT use recursion. public class Node { public int data; public Node next; }...
Do not use awk. Using the fixed length field file called famous.dat, make a one-line Unix...
Do not use awk. Using the fixed length field file called famous.dat, make a one-line Unix command - using pipe(s) - to display an alphabetical list of the last and first names in upper case of the last 8 people in the file. Hint: Names are in columns 6 through 35. Output is this.. DARWIN         CHARLES       EINSTEIN       ALBERT        GALILEO        GALILELI      GOLDMAN        EMMA          LOVELACE       ADA           MANDELA        NELSON        PARKS          ROSA          RUSSELL        BERTRAND Hint:  famous.dat uses space(s) to separate the fields
Create a method that returns the third character from the String word. Be sure to use...
Create a method that returns the third character from the String word. Be sure to use a try catch block and use the appropriate exception to deal with indexes out of a String’s bound: StringIndexOutOfBoundsException. Return the character 'x' (lowercase) when this exception is caught. Do not use if statements and do not use the general exception handler Exception. Examples: thirdLetter("test") -> 's' public char thirdLetter(String word) { } ​should return the char 'r'
A. Open/create the file bank.txt for writing "w". Enter a character from the keyboard and write...
A. Open/create the file bank.txt for writing "w". Enter a character from the keyboard and write it to the file. Close the file. In the same program open the file for reading "r" and read the character from the file and print it on screen.
1- Use LinkList. Write removeLast(n). Delete the last occurrence of an item from a linked list....
1- Use LinkList. Write removeLast(n). Delete the last occurrence of an item from a linked list. So if the item is 7 and the list is [1,3,7,4,7,3,7,2], the result is [1,3,7,4,7,3,2] 2- Use LinkList. Write removeAll(int n). Deletes all occurrences of an item n from a linked list. So if the item is 7 and the list1 is [1,3,7,4,7,3,2] , then list1.removeAll(7) then list1 becomes [1,3,4,3,2]. Demonstrate by displaying the list contents before and after calling the above methods. Eg:...
1- Use LinkList. Write removeLast(n). Delete the last occurrence of an item from a linked list....
1- Use LinkList. Write removeLast(n). Delete the last occurrence of an item from a linked list. So if the item is 7 and the list is [1,3,7,4,7,3,7,2], the result is [1,3,7,4,7,3,2] 2- Use LinkList. Write removeAll(int n). Deletes all occurrences of an item n from a linked list. So if the item is 7 and the list1 is [1,3,7,4,7,3,2] , then list1.removeAll(7) then list1 becomes [1,3,4,3,2]. Demonstrate by displaying the list contents before and after calling the above methods. Eg:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT