My argument has data as below.
10.9.9.85
-rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr5.scr 127869538
-rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr56scr 127869538
....... (note all these between lines will start with hyphen '-' )
-rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr9.scr 127869538
10.9.9.140
-rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr5.scr 127869538
-rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr6.scr 127869538
....... (note all these between lines will start with hyphen '-' )
-rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr9.scr 127869538
myhost1
-rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr5.scr 127869538
-rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr6.scr 127869538
....... (note all these between lines will start with hyphen '-' )
-rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr9.scr 127869538
..... (and so on)
This is how i run the script:
./readfile.sh '10.9.9.85\\n-rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr5.scr 127869538\\n-rwxr-xr-x user1 2019-10-15 17:40 /app/mrt/testingscr6.mrt 4119663872\\n-rwxr-xr-x user1 2019-10-15 17:40 /app/exe/testingscr9.exe 1799452894\\n10.9.9.140\\n-rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr5.scr 127869538\\n-rwxr-xr-x user1 2019-10-15 17:40 /app/mrt/testingscr6.mrt 4119663872\\n-rwxr-xr-x user1 2019-10-15 17:40 /app/exe/testingscr9.exe 1799452894'
I wish to get the the filenames between the first IP/hostname and the next IP/hostname only i.e between the first and second IP / Host specified.
Desired Output:
/app/scripts/testingscr5.scr
/app/scripts/testingscr6.scr
.......
/app/scripts/testingscr9.scr
below is what i did so far:
#!/bin/ksh
VAR1=`echo "${1}" | sed -e "s/'//g"`
echo "${VAR1}" |
while IFS=' '
read -r dirpath
do
fileis=`echo "$dirpath" | awk -F' ' '{ print $5 }'`
echo "FILE IS:$fileis"
done
The above prints all file names but I m not able to get the logic of how can I filter filenames between the first IP/Hostname and the SecondOne only ... store it in a variable.
Note: There maybe a case where we do not have a second IP / Hostname in which case we need to get the filename after the first IP / Hostname only.
Tip: we can look for strings starting with hyphen '-' to know if that is a file entry.
I'm using ksh shell on AiX 6.1