Sponsored Content
Top Forums Shell Programming and Scripting Logic to separate the first name in the file Post 302999437 by ricky-row on Tuesday 20th of June 2017 08:21:12 AM
Old 06-20-2017
I have made this function in script, I need to use the VAR in other way after the function, do you have any idea how to do that

if there are 10 files with *.rpm, I need to store the VAR values like abc, xy-z, etc.. in a new file. So, after this function I have to check for the file existence first, if not have to create a file named test.txt.
then inside the file
Code:
NAME = abc 
TYPE = txt

for all the 10 fiiles.
NOTE: if already the file is existing it can overwrite the same file but 11th file is added it should not delete the existing in the test.txt, it should be added at the end.

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


Moderator's Comments:
Mod Comment
Please wrap all code, files, input & output/errors in CODE tags.
it makes it easier to read and preserves spaces for indenting or fixed-width data.

Last edited by rbatte1; 06-20-2017 at 10:47 AM.. Reason: Added CODE tags
 

We Also Found This Discussion For You

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
INFO(1)                                                            User Commands                                                           INFO(1)

NAME
info - read Info documents SYNOPSIS
info [OPTION]... [MENU-ITEM...] DESCRIPTION
Read documentation in Info format. Frequently-used options: -a, --all use all matching manuals -k, --apropos=STRING look up STRING in all indices of all manuals -d, --directory=DIR add DIR to INFOPATH -f, --file=MANUAL specify Info manual to visit -h, --help display this help and exit --index-search=STRING go to node pointed by index entry STRING -n, --node=NODENAME specify nodes in first visited Info file -o, --output=FILE output selected nodes to FILE -O, --show-options, --usage go to command-line options node --subnodes recursively output menu items -v, --variable VAR=VALUE assign VALUE to Info variable VAR --version display version information and exit -w, --where, --location print physical location of Info file The first non-option argument, if present, is the menu entry to start from; it is searched for in all 'dir' files along INFOPATH. If it is not present, info merges all 'dir' files and shows the result. Any remaining arguments are treated as the names of menu items relative to the initial node visited. For a summary of key bindings, type H within Info. EXAMPLES
info show top-level dir menu info info-stnd show the manual for this Info program info emacs start at emacs node from top-level dir info emacs buffers select buffers menu entry in emacs manual info emacs -n Files start at Files node within emacs manual info '(emacs)Files' alternative way to start at Files node info --show-options emacs start at node with emacs' command line options info --subnodes -o out.txt emacs dump entire emacs manual to out.txt info -f ./foo.info show file ./foo.info, not searching dir REPORTING BUGS
Email bug reports to bug-texinfo@gnu.org, general questions and discussion to help-texinfo@gnu.org. Texinfo home page: http://www.gnu.org/software/texinfo/ COPYRIGHT
Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
The full documentation for info is provided by the texinfo-doc-nonfree package as a Texinfo manual. If this package is installed at your site, the command info info should give you access to the complete manual. (Or, if you have Emacs, M-x info will lead to the manual.) info 6.5 February 2018 INFO(1)
All times are GMT -4. The time now is 08:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy