我想在pass_flag的echo命令中传递test_var

时间:2016-01-10 14:56:52

标签: shell unix awk

我正在解析XML文件users.xml,我希望将保存密码值的$3传递给trial.sh。 XML文件如下所示:

<Users>
<user>
<name>Veera</name>
<password>!#!veera@nbs</password>
</user>
</Users>
  awk '
    BEGIN { FS = "[<|>]" }
    {
           if ($2 == "password") 
           {
               if($3=="!#!veera@nbs")
                {
                   encrypted="'"`sh test.sh $3`"'" 
                   sub($3,encrypted)
                }
           }
            print
    }
    ' users.xml > users2.xml

XML文件包含元素password$3包含我要传递给加密trial.sh$3)的!#!veera@nbs的新密码,返回结果,该结果将存储在加密的awk变量中,并替换现有值。

1 个答案:

答案 0 :(得分:0)

public  class SongDetailFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor>{
    private  Song song;
    private static final int CURSOR_LOADER_ID = 0;
    ImageButton imgViewFavButton;
    Boolean mIsFavourite = false;

   // private final Context mContext;

    public SongDetailFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.song_fragment_detail, container, false);


        Intent intent = getActivity().getIntent();
        if (intent != null && intent.hasExtra("song")) {


            song = intent.getParcelableExtra("song");
            //display title
            ((TextView) rootView.findViewById(R.id.detail_title_textview))
                    .setText(song.getTitle());

            ((TextView)rootView.findViewById(R.id.detail_description_textview))
                    .setText(song.getDescription());


            ((TextView)rootView.findViewById(R.id.song_releasedate_textview))
                    .setText(song.getReleaseDate());

            double dRating = song.getVoteAverage();
            String sRating = String.valueOf(dRating);

            ((TextView)rootView.findViewById(R.id.song_rating_textview))
                    .setText(sRating + "/10 ");

            //show song poster


            ImageView imageView = (ImageView) rootView.findViewById(R.id.song_detail_poster_imageview);
            Picasso.with(getActivity()).load(song.getPoster()).into(imageView);
        }

        imgViewFavButton = (ImageButton) rootView.findViewById(R.id.imgFavBtn);

        checkFavourites();

        imgViewFavButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {

                if  (mIsFavourite) {

                   deleteFromDB();

                }

                else {
                    insertData();
                    mIsFavourite = true;
                }


            }
        });

        return rootView;
    }

    // insert data into database

    public void insertData(){
        ContentValues songValues = new ContentValues();
        songValues.put(SongContract.SongEntry.COLUMN_ID, song.getsong_id());
        songValues.put(SongContract.SongEntry.COLUMN_IMAGE, song.getPoster());
        songValues.put(SongContract.SongEntry.COLUMN_TITLE, song.getTitle());
        songValues.put(SongContract.SongEntry.COLUMN_OVERVIEW, song.getDescription());
        songValues.put(SongContract.SongEntry.COLUMN_RELEASEDATE, song.getReleaseDate());
        songValues.put(SongContract.SongEntry.COLUMN_RATING, song.getVoteAverage().toString());

           //Insert our ContentValues
        getActivity().getContentResolver().insert(SongContract.SongEntry.CONTENT_URI,
                songValues);

         imgViewFavButton.setImageResource(android.R.drawable.btn_star_big_on);

    }

    private void deleteFromDB() {

        ContentValues songValues = new ContentValues();


        getActivity().getContentResolver().delete(SongContract.SongEntry.CONTENT_URI,
                SongContract.SongEntry.COLUMN_TITLE + " = ?",
                new String[]{songValues.getAsString(song.getTitle())});


        imgViewFavButton.setImageResource(android.R.drawable.btn_star_big_off);
    }



    private void checkFavourites() {
        Cursor c =
                getActivity().getContentResolver().query(SongContract.SongEntry.CONTENT_URI,
                        null,
                        SongContract.SongEntry.COLUMN_ID + " = ?",
                        new String[]{song.getsong_id()},
                        null);

        if (c != null) {
            c.moveToFirst();
            int index = c.getColumnIndex(SongContract.SongEntry.COLUMN_ID);

            if (c.getCount() > 0 && c.getString(index).equals(song.getsong_id())) {
                mIsFavourite = true;
                imgViewFavButton.setImageResource(android.R.drawable.btn_star_big_on);
            }

            else{
                imgViewFavButton.setImageResource(android.R.drawable.btn_star_big_off);
            }

            c.close();

        }



    }


    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args){
        return new CursorLoader(getActivity(),
                SongContract.songEntry.CONTENT_URI,
                null,
                null,
                null,
                null);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState){
        super.onViewCreated(view, savedInstanceState);
    }


    // Set the cursor in our CursorAdapter once the Cursor is loaded
    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {




    }

    // reset CursorAdapter on Loader Reset
    @Override
    public void onLoaderReset(Loader<Cursor> loader){

    }

}

这样:

$ awk -F'</?password>' 'NF>1{print $2}' file
!#!veera@nbs

以上假设您的文件总是与您的示例所显示的一样,并且没有(例如)与标记不同的行上的密码值。