-3

I have Data which is in this format in FILE1.txt

@E/f1/w/ @H/abc/w/ @demo/file/wk/Fil0.fk
@E/f2/w/ @H/cdv/w/ @demo/file/wk/Fil1.fk
@E/f3/w/ @H/efg/w/ @demo/file/wk/Fil2.fk
@E/f4/w/ @H/mno/w/ @demo/file/wk/Fil3.fk
@E/f5/w/ @H/pqr/w/ @demo/file/wk/Fil4.fk

I want to Print data to a File .... FILE2.txt in this Below Format

Fil0.fk
Fil1.fk
Fil2.fk
Fil3.fk
Fil4.fk
jww
  • 97,681
  • 90
  • 411
  • 885
  • As Ulrich asked in your [other question](https://stackoverflow.com/questions/56393207/remove-match-word-from-file#comment99385356_56393207) (and [here](https://stackoverflow.com/q/56394666/608639)), please pick a programming language or general text processing tool. As a new user, please take the [tour](https://stackoverflow.com/tour) and read [How to Ask](https://stackoverflow.com/questions/how-to-ask) as well. – jww May 31 '19 at 13:08
  • 1
    How could you not get from your other question that you just need to increase the number of / after which to cut !? – B. Go May 31 '19 at 13:13

2 Answers2

0

Welcome to StackOverflow.

I Assuming that you want to save the first and second columns in new files.

You have to create a bash like bellow in the path where the FILE1.txt exists, change it to an executable file with chmod +x <bash_file_name> command and run it by ./<bash_file_name>

#!/bin/bash

input="FILE1.txt"
while IFS= read -r line
do
    # Extract file name
    filename=`echo "$line" | awk '{print $3}' | cut -d'/' -f4`

    # Extract data
    clumnOne=`echo "$line" | awk '{print $1}'`
    clumnTwo=`echo "$line" | awk '{print $2}'`

    # Write to file
    echo "$clumnOne $clumnTwo" >> $filename
done < "$input"
Ali Golbin
  • 77
  • 3
  • it gives me this error ... f.sh: line 28: $filename: ambiguous redirect – volmokirti May 31 '19 at 13:59
  • The script provided by Ali only has 16 lines. It is not possible to have an error on line 28. You need to show your code, and clearly state where you are having trouble. – jww May 31 '19 at 14:54
  • This is because you probably changed the script for your use, please show your script and text file for solving. – Ali Golbin Jun 01 '19 at 03:27
-1

Always show what you tried.

Assuming filename x,

with cut:

$: cut -d/ -f 10 x

with sed:

$: sed 's#^.*/##' x

with awk:

$: awk  ' { gsub("^.*/",""); print; }' x

pure bash:

$: while read line; do echo "${line//*\/}"; done < x
Paul Hodges
  • 13,382
  • 1
  • 17
  • 36