Logic to separate the first name in the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Logic to separate the first name in the file
# 8  
Old 06-21-2017
Hi, any idea on this?
# 9  
Old 06-21-2017
Do not call a function test. test is a command to check file types and compare values.
# 10  
Old 06-21-2017
oh, sorry. test is for explanation, I have my different function, its just for explaining the scenario
# 11  
Old 06-21-2017
maybe have the function return the value. ex:
Code:
VAR=111

func()
{
  v=222
  echo $v
}

VAR=$(func)

echo $VAR

# 12  
Old 06-21-2017
No, sorry
The value of VAR should be the input of my question

---------- Post updated at 09:17 PM ---------- Previous update was at 09:06 PM ----------

Code:
test()
{
  pushd packages &>/dev/null
  mkdir -p ../info
  for p in $(ls *.rpm 2>/dev/null);do
    VAR=($(echo $p| sed 's/-[0-9].*//';))
    if [ -e /info/$VAR.list} ]; then continue;fi
      rpm -qlp $p | sed -re 's/^/./' > /info/$VAR.list};;
    esac
  done
  popd &>/dev/null
}
test

After this function, let there are 10 files with .rpm extension has been parsed and saved with $VAR.list .
Now the other function should take the all the 10 values of VAR i.e the function can be called inside the test() function.

that VAR value has to be written inside a file name test.txt
ex: $cat test.txt
NAME=abc
NAME=xyz......
# 13  
Old 06-21-2017
To repeat: Do not name a function test -- ever. Name it test2 if you have to, never test. There's a real command named test which will pop up when you're not expecting it.

This is redundant:
Code:
for p in $(ls *.rpm 2>/dev/null);do

Just do:
Code:
for p in .rpm ;do

I have no idea what that esac is doing as you're not using case, that's got to be a syntax error.

I think you mean popd >/dev/null 2>/dev/null not popd &>/dev/null.

I think you mean [ -e ../info/$VAR.list ] not [ -e /info/$VAR.list} ]

How about
Code:
cat ../info/* > outputfile

# 14  
Old 06-21-2017
Thanks for the quick reply, The corrections given by you are correct, I will make changes. But the last which you said.
Code:
cat ../info/* > outputfile

I can't understand it., where I have to implement it and how it will collect all the values of VAR
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies
Login or Register to Ask a Question