D
D
Demigodd2018-03-08 15:10:48
bash
Demigodd, 2018-03-08 15:10:48

How to get folder name + file text name + what is written inside?

home/folder1/folder2
home/folder1/file1.txt
home/folder1/folder2/file2.txt
output:
folder1:file1.txt : [what is written inside the text file]
folder2:file2.txt : [what is written inside the text file ]

My code

#!/bin/bash

ff=`find ./* -name "*.txt"`
#fd=`find ./ -type d | grep -o '[^/]*$'`

for i in $ff
do
echo "${i} : $(cat ${i})"
done

output:
./home/folder1/file1.txt : asd
./home/folder1/folder2/file2.txt : dsa

What am I doing wrong?
How to get folder name + file text name + what is written inside ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AVKor, 2018-03-08
@Demigodd

man basename
man dirname
man awk

The last one is about the F option and the NF variable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question